vb.net - vb 应用程序中的按钮在第一次单击后在循环中每 x 次按下自身
问题描述
这是我的按钮,只需要知道我对 vb.net 很陌生
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
解决方案
最好在单击按钮时调用方法,而不是将代码放在那里 - 特别是如果您希望“每 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
推荐阅读
- oracle - 作为系统用户,我遇到此错误:ORA-01031:权限不足
- kubernetes - 自定义值时,kubernetes cronjob 无法正常工作
- python - Python。将两个列表组合在同一长度内
- asp.net-core - 授权:如何处理多个(十几个或更多)需求
- c - Pi 3 上的 perf_event.h 事件组是否有多重限制
- linux - 当 $EUID 与 $UID 不同时,我如何产生一种情况?
- html - 我尝试验证我的 css 文件,但找不到将网格布局调整为平板电脑大小的问题
- python - read_csv 不会打开 .csv 文件;而是必须使用 csv.reader+defaultdict 在框架中解析
- javascript - 无法获得 PERT 图形结果 - AnyChart JS
- node.js - buildpack 将 node.js 应用程序部署到 heroku 时出错 - 文件似乎处于正确的级别>?