我试图从一个独立的子过程中引用 KeyDown 事件,并让它循环回到原来的独立子过程中。
- 在独立子过程中开始(DisplayAction - 然后调用 KeyDown 事件)
- 进入 KeyDown 事件(KeyDown 然后调用 DisplayAction)
- 返回原始子过程(DisplayAction)并继续循环。
*步骤 1 和 2 在我的代码中运行良好。第3步是问题。我的程序不会循环回到独立的子程序。
Public Class frmMain
Dim RandomNumber As Integer
Dim RandomNumbers(1000) As Integer
Dim intAction As Integer
Dim strAction1 As String = "A"
Dim strAction2 As String = "B"
Dim strAction3 As String = "C"
Dim strAction4 As String = "D"
Dim i As Integer
Private Sub frmMain_Load(sender As Object, e As System.EventArgs) Handles Me.Load
FormLoad(sender, e)
End Sub
Private Sub FormLoad(sender, e)
'Creates random numbers here
DisplayAction(sender, e)
End Sub
Public Sub DisplayAction(sender, e)
For i As Integer = 0 To 3
Select Case lstRandom.Items(i)
Case 1
lblDisplay.Text = strAction1
intAction = 1
frmMain_KeyDown(Sender, intAction = 1)
Case 2
lblDisplay.Text = strAction2
intAction = 2
frmMain_KeyDown(sender, intAction = 2)
Case 3
lblDisplay.Text = strAction3
intAction = 3
frmMain_KeyDown(sender, intAction = 3)
Case 4
lblDisplay.Text = strAction4
intAction = 4
frmMain_KeyDown(sender, intAction = 4)
End Select
Next i
End Sub
Private Sub frmMain_KeyDown(sender, e) Handles Me.KeyDown
If intAction = 1 Then
lblDisplay.Text = "works! 1"
Call DisplayAction(sender, e)
ElseIf intAction = 2 Then
lblDisplay.Text = "works! 2"
Call DisplayAction(sender, e)
ElseIf intAction = 3 Then
lblDisplay.Text = "works! 3"
DisplayAction(sender, e)
ElseIf intAction = 4 Then
lblDisplay.Text = "works! 4"
DisplayAction(sender, e)
End If
End Sub
End Class