vb 怎么用一个按钮控制另一个按钮重复点击执行?
展开全部
很简单啊,通过一个变量来控制啊,比如定义一个变量a,当button2点一次的时候就变化一次,具体代码可以这样写:
dim
a
as
integer
a=1(在申明中定义就行)
Private
Sub
ToggleButton2_Click()
if(a=1)
then
Controls("CMD_fireall").Value
=
True
a=2
elseif(a=2)
Controls("CMD_fireall").Value
=
False
a=1
end
if
End
Sub
就是这个意思,通过这个变量去控制,然后每次修改变量名,就实现了这种点一次循环,再点一次停止的效果
dim
a
as
integer
a=1(在申明中定义就行)
Private
Sub
ToggleButton2_Click()
if(a=1)
then
Controls("CMD_fireall").Value
=
True
a=2
elseif(a=2)
Controls("CMD_fireall").Value
=
False
a=1
end
if
End
Sub
就是这个意思,通过这个变量去控制,然后每次修改变量名,就实现了这种点一次循环,再点一次停止的效果
展开全部
最简单的办法加一个timer1控件,代码如下:
Private
Sub
Form_Load()
Timer1.Enabled
=
False
'初始timer1的状态为未激活
Timer1.Interval
=
1000
'初始timer1代码的执行周期为1000毫秒
End
Sub
Private
Sub
Timer1_Timer()
CMD_fireall_Click
End
Sub
Private
Sub
ToggleButton2_Click()
Timer1.Enabled
=
Not
Timer1.Enabled
End
Sub
如果不用timer控件也可以写成
Dim
TmpState
As
Boolean
Private
Sub
Form_Load()
TmpState
=
False
End
Sub
Private
Sub
ToggleButton2_Click()
TmpState
=
Not
TmpState
LoopClick
End
Sub
Private
Sub
LoopClick()
While
TmpState
=
True
DoEvents
CMD_fireall_Click
Wend
End
Sub
但是这样循环点击就是没有间隔的快速循环,如果需要间隔时间就写成:
Private
Declare
Function
timeGetTime
Lib
"winmm.dll"
()
As
Long
Dim
TmpState
As
Boolean
Private
Sub
Form_Load()
TmpState
=
False
End
Sub
Private
Sub
ToggleButton2_Click()
TmpState
=
Not
TmpState
LoopClick
End
Sub
Private
Sub
LoopClick()
Dim
TimeA
As
Long
TimeA
=
timeGetTime
While
TmpState
=
True
DoEvents
If
timeGetTime
-
TimeA
>=
1000
Then
‘设置间隔时间为1000毫秒
CMD_fireall_Click
TimeA
=
timeGetTime
End
If
Wend
End
Sub
Private
Sub
Form_Load()
Timer1.Enabled
=
False
'初始timer1的状态为未激活
Timer1.Interval
=
1000
'初始timer1代码的执行周期为1000毫秒
End
Sub
Private
Sub
Timer1_Timer()
CMD_fireall_Click
End
Sub
Private
Sub
ToggleButton2_Click()
Timer1.Enabled
=
Not
Timer1.Enabled
End
Sub
如果不用timer控件也可以写成
Dim
TmpState
As
Boolean
Private
Sub
Form_Load()
TmpState
=
False
End
Sub
Private
Sub
ToggleButton2_Click()
TmpState
=
Not
TmpState
LoopClick
End
Sub
Private
Sub
LoopClick()
While
TmpState
=
True
DoEvents
CMD_fireall_Click
Wend
End
Sub
但是这样循环点击就是没有间隔的快速循环,如果需要间隔时间就写成:
Private
Declare
Function
timeGetTime
Lib
"winmm.dll"
()
As
Long
Dim
TmpState
As
Boolean
Private
Sub
Form_Load()
TmpState
=
False
End
Sub
Private
Sub
ToggleButton2_Click()
TmpState
=
Not
TmpState
LoopClick
End
Sub
Private
Sub
LoopClick()
Dim
TimeA
As
Long
TimeA
=
timeGetTime
While
TmpState
=
True
DoEvents
If
timeGetTime
-
TimeA
>=
1000
Then
‘设置间隔时间为1000毫秒
CMD_fireall_Click
TimeA
=
timeGetTime
End
If
Wend
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果是一个工程里的2个窗体,调用时需要先将第二个窗体中按钮的事件作用域private改为public
。然后在第一个窗体中的控件单击事件里调用窗体名+事件名。例如:
form1中:
private
sub
command1_click()
form2.command1_click
end
sub
form2中:
public
sub
command1_click()
'这里是第二个窗体中按钮的单击事件’
end
sub
。然后在第一个窗体中的控件单击事件里调用窗体名+事件名。例如:
form1中:
private
sub
command1_click()
form2.command1_click
end
sub
form2中:
public
sub
command1_click()
'这里是第二个窗体中按钮的单击事件’
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询