我在我的代码中使用Application.DoEvents()
以便我可以按下按钮退出循环,我遇到一个问题,我必须先点击屏幕才能按下此退出按钮,因此需要两个点击。每当我玩游戏然后试图停止程序而不关闭程序时就会发生这种情况。我该如何解决这个问题?
Do While StopProgram = False
Application.DoEvents()
RadianAngle = Angle * PlaceHolder
Me.Refresh()
If DirectionPositive = False Then
Angle += 1
If Angle = 51 Then
Angle = 49
DirectionPositive = True
End If
ElseIf DirectionPositive = True Then
Angle -= 1
If Angle = -51 Then
Angle = -49
DirectionPositive = False
End If
End If
Loop
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
StopProgram = False
RunningProgram()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
StopProgram = True
End Sub
答案 0 :(得分:1)
一种解决方法:如果您使用MouseDown而不是Click事件,它将正常工作。