我会保留一系列按钮:
Private buttons() As Button = { Me.Button1, Me.Button2, Me.Button3, … }
您可以制作一个处理程序:
Private Sub Button_Click(sender As Object, e As EventArgs)
' TODO
End Sub
将处理程序添加到中的按钮New()
:
Public Sub New()
Me.InitializeComponent()
For Each b In buttons
AddHandler b.Click, AddressOf Button_Click
Next
End Sub
在这样做之后(或之前),随机化buttons
. 然后跟踪您希望用户单击的下一个:
Private currentButton As Integer = 0
在处理程序中,检查:
If sender Is buttons(currentButton) Then
' Move to the next button
currentButton += 1
' Was that the end of them?
If currentButton = buttons.Length Then
' All buttons were pressed in the right order
End If
Else
' Wrong!
End If
您可以使用列表,但如果您知道每个按钮与您已有的订单相匹配,您实际上并不需要跟踪按下的每个按钮。