Private Sub Command1_Click() For i = 0 To 100 For j = 0 To 100 For k = 0 To 100 DoEvents Next Next Next MsgBox "hello" End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) MsgBox "ok" End Sub '我的意思先出现 ok 后出现 hello
注意的是:我的CPU是1.2G,延迟差不多2秒左右 所以请根据你的电脑调节一下循环次数
>>用以下这两个sub可以知道,先是click然后再是mouseup,我认为消息就是这么响应的。Private Sub Command1_Click() List1.AddItem "Click" End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) List1.AddItem "Mouse Up" End Sub>>如果要人为地改变这个次序,可以写一个过程来实现click的代码,然后在mouseup中调用一下。比如:Private Sub Clone_Command1_Click() List1.AddItem "Click" End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) List1.AddItem "Mouse Up" Clone_Command1_Click End Sub>>还有一个稍微复杂点的方法,在click和mouseup中各加一个线程,大致如下: sub click 启动thread 1 end subsub mouseup 启动thread 2 end subcallback thread1 wait for thread 2的结束标志 action clear thread2 的结束标志 end callbackcallback thread2 设置thread2的启动标志 action 设置thread2的结束标志 end callback
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Debug.Print "MouseUp" End SubPrivate Sub Timer1_Timer() Timer1.Enabled = fasle For i = 1 To 100 For j = 1 To 100 DoEvents Next j Next i Debug.Print "Click" End Sub 可以看到运行后,先在debug窗口先输出 Mouseup, 然后才是click
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) For i = 0 To 100 For j = 0 To 100 For k = 0 To 100 DoEvents Next Next Next MsgBox "hello" End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) MsgBox "ok" End Sub '我的意思先出现 ok 后出现 hello
For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
DoEvents
Next
Next
Next
MsgBox "hello"
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "ok"
End Sub '我的意思先出现 ok 后出现 hello
所以请根据你的电脑调节一下循环次数
List1.AddItem "Click"
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.AddItem "Mouse Up"
End Sub>>如果要人为地改变这个次序,可以写一个过程来实现click的代码,然后在mouseup中调用一下。比如:Private Sub Clone_Command1_Click()
List1.AddItem "Click"
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.AddItem "Mouse Up"
Clone_Command1_Click
End Sub>>还有一个稍微复杂点的方法,在click和mouseup中各加一个线程,大致如下:
sub click
启动thread 1
end subsub mouseup
启动thread 2
end subcallback thread1
wait for thread 2的结束标志
action
clear thread2 的结束标志
end callbackcallback thread2
设置thread2的启动标志
action
设置thread2的结束标志
end callback
我不知道线程怎样用,谢谢告诉我
vb是单线程的,而Click 事件先于mouseup事件发生,所以,必然是
先执行了click中的所有操作再去执行mouseup的操作。
如果要想做到楼主的要求,可以用timer来做。Private Sub Command1_Click()
Timer1.Interval = 1
Timer1.Enabled = True
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "MouseUp"
End SubPrivate Sub Timer1_Timer()
Timer1.Enabled = fasle
For i = 1 To 100
For j = 1 To 100
DoEvents
Next j
Next i
Debug.Print "Click"
End Sub
可以看到运行后,先在debug窗口先输出 Mouseup, 然后才是click
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 0 To 100
For j = 0 To 100
For k = 0 To 100
DoEvents
Next
Next
Next
MsgBox "hello"
End SubPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "ok"
End Sub '我的意思先出现 ok 后出现 hello