如何在单击主窗体上的按钮时更改辅助窗体上按钮的功能

时间:2015-07-25 03:26:20

标签: vb.net winforms button

我制作了一个程序,我希望将form2上的按钮链接起来,根据我在form1中单击的按钮播放不同的声音。

怎么可能这样做?

1 个答案:

答案 0 :(得分:0)

Form1.vb的

Public beepButtonClicked As Boolean = False
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    beepButtonClicked = True
End Sub

Form2.vb

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If Form1.beepButtonClicked = True Then
        MessageBox.Show("Button clicked after beepButton was clicked")
    End If
End Sub

或者如果你想要多个声音:

Form1.vb的

Public beepButtonClicked As String = "sounds/sound1.wav"
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    beepButtonClicked = "sounds/sound2.wav"
End Sub

Form2.vb

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    axWindowsMediaPlayer1.URL = beepButtonClicked
End Sub