如何实现鼠标按住一按钮不放,则循环执行一程序;鼠标抬起,则循环程序停止?

eeyyllehs 2009-07-03 03:40:54
如题
...全文
115 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
eeyyllehs 2009-07-06
  • 打赏
  • 举报
回复
一楼的方法可以,不过循环的太快了。
如何加上时间延迟呢?我可了网上说用SLEEP 500;比较方便,可系统报错未知函数。
贝隆 2009-07-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mhm0517 的回复:]
VB code'增加一个按扭,你按在按扭上试一下/Dim isStopAsBooleanPrivateSub Command1_MouseDown(ButtonAsInteger, ShiftAsInteger, XAsSingle, YAsSingle)
isStop=TrueWhile isStop
Me.Caption=Now
DoEventsWendEnd SubPri¡­
[/Quote]

这个是正解
chenvb 2009-07-03
  • 打赏
  • 举报
回复
楼上的都说了,楼主自己看着办吧.
jhone99 2009-07-03
  • 打赏
  • 举报
回复
修改下

Dim blnRun As Boolean

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not blnRun Then
blnRun = True
Call subDo
End If

End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnRun Then
blnRun = False
End If

End Sub

Private Sub subDo()
Dim i As Long

While blnRun
i = i + 1
Debug.Print i
DoEvents
Wend

End Sub
码之魂 2009-07-03
  • 打赏
  • 举报
回复
忽忽,都对!楼主自己看着办吧.
jhone99 2009-07-03
  • 打赏
  • 举报
回复
Dim blnRun As Boolean
Dim blnStop As Boolean

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not blnRun Then
blnRun = True
Call subDo
End If

End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If blnRun Then
blnStop = True
End If

End Sub

Private Sub subDo()
Dim i As Long

While Not blnStop
i = i + 1
Debug.Print i
DoEvents

Wend

End Sub
mhm0517 2009-07-03
  • 打赏
  • 举报
回复
'增加一个按扭,你按在按扭上试一下/
Dim isStop As Boolean

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
isStop = True
While isStop
Me.Caption = Now
DoEvents
Wend
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
isStop = False
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧