当我们在事件里面进行大量的循环操作时,windows将等待循环结束。此时界面是得不到响应的。为了在WinForm界面上实时地显示每次循环得到的结果,可以用.net提供的Application.DoEvents()。
Public Class Form1
Private Sub wndButtonGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wndButtonGo.Click
Dim i As Integer
For i = 0 To 10000
Me.wndTextBoxMsg.Text = i.ToString
Next
End Sub
Private Sub wndButtonDoEvents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles wndButtonDoEvents.Click
Dim i As Integer
For i = 0 To 10000
Me.wndTextBoxMsg.Text = i.ToString
Application.DoEvents() ' 使窗体界面实时响应
Next
End Sub
End Class