How to do something while mousedown is true
example: Decrement the year while a label mousedown event is true, & stop decrement after releasing the mouse button
Printable View
How to do something while mousedown is true
example: Decrement the year while a label mousedown event is true, & stop decrement after releasing the mouse button
Place a timer at your form. set the clock to execute the decrement every, say, 1 sec, by seting it's Interval property to 1000 (ms).
Now disable the timer at designtime and add these events:
Code:Private Sub Label1_MouseDown(....)
Timer1.Enabled = True
End Sub
Private Sub Label1_MouseUp(....)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
count = count - 1
End Sub
yosef, I don't think we really need a Timer for this simple task. If you affraid the Label1.Caption change too fast, then you can perform a delay by calling the Sleep API like what I've did.
Code:Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private IsMouseDown As Boolean
Private Sub Form_Load()
IsMouseDown = False
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
IsMouseDown = True
Do While IsMouseDown
Label1.Caption = Val(Label1.Caption) - 1
Sleep 250 'delay 250ms
DoEvents
Loop
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
IsMouseDown = False
End Sub
Chris
Your solution works well with slight modification in my app
without the overhead of a timer.
Thanks