大家好!VB.net VS2010,如何捕捉任意按钮的按下事件?
发布网友
发布时间:2024-10-06 20:54
我来回答
共2个回答
热心网友
时间:2024-12-01 07:45
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each Item As Control In Controls
If TypeOf Item Is Button Then
AddHandler Item.Click, AddressOf Buts
End If
Next
End Sub
Sub Buts(ByVal sender As System.Object, ByVal e As System.EventArgs)
AllE_D(False)
Timer1.Interval = 60000
Timer1.Enabled = True
End Sub
Sub AllE_D(ByVal e_d As Boolean)
For Each Item As Control In Controls
Item.Enabled = e_d
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
AllE_D(True)
End Sub
热心网友
时间:2024-12-01 07:45
private buclick (.....) ...handles b1.click, b2.click, b3.click
再拉一个timer控件,时间设为6000,在buclick下写
timer1.enable=true
b1.enable=f
b2.enable=f
........
timer.tick下写
timer1.enable=f
b1.enable=t
b2.enable=t
........追问谢谢你!
可是我的窗体里按钮太多,几十个,名字可能也不规则,我不想一个一个在触发条件里添加,有没有更好的办法?
追答上面写了呀,就是写一个sub然后后面handles所有button的click就好了,然后sub里写一边所有的button的enable=f/t就行了,要真的不想这么写就要写遍历me.control集合里button然后声明click事件……略烦,代码今晚就写不出来了……嗯,就是这样。代码我明天试着写写。