0
單擊下面的代碼中的開始按鈕後,窗體失去焦點,表單似乎失去焦點,我需要點擊兩次停止按鈕停止計數。 (首先點擊激活表單,然後點擊按鈕)有人可以解釋這種行爲或提供更好的選擇?單擊按鈕
Public Class Form1
Dim testrunning As Boolean
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
testrunning = True
test()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
testrunning = False
End Sub
Private Sub test()
Dim count As Integer
While testrunning = True
count += 1
TextBox1.Text = count.ToString
System.Threading.Thread.Sleep(100)
Application.DoEvents()
End While
End Sub
End Class