【发布时间】:2018-10-08 15:24:21
【问题描述】:
这是我的按钮,只需要知道我对 vb.net 很陌生
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
【问题讨论】:
-
即使是一个糟糕的教程也会涵盖这种入门级别的问题
标签: vb.net
这是我的按钮,只需要知道我对 vb.net 很陌生
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
【问题讨论】:
标签: vb.net
最好在按钮点击中调用方法,而不是将代码放入其中 - 特别是如果您希望“每 x 次”执行一次点击。
Dim timer As New System.Threading.Timer(AddressOf doClickStuff)
Dim interval As Integer = 1000 ' 1000 ms = 1 second
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
doClickStuff()
End Sub
Private Sub doClickStuff()
If Me.InvokeRequired Then
Me.Invoke(New Action(AddressOf doClickStuff))
Else
' do stuff here
timer.Change(interval, -1)
End If
End Sub
'' if you won't access UI elements in "do stuff here"
'' you can use this method which will run on a non-UI thread
'Private Sub doClickStuff()
' ' do stuff here
' timer.Change(interval, -1)
'End Sub
' stops the timer
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
timer.Change(-1, -1)
End Sub
【讨论】: