indy500fan
asked on
How do I have a button repeat an action for as long as I have the button depressed?
Friends,
I tried the following, but it never stopped the process when I released the mouse button:
Private Sub btnFaster_Hold(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles btnFaster.MouseDown
While Control.MouseButtons() = Windows.Forms.MouseButtons .Left
If tbSpeedThreshold.Value < 20 Then
tbSpeedThreshold.Value += 1
System.Threading.Thread.Sl eep(500)
If Control.MouseButtons. = Windows.Forms.MouseButtons .None Then
SetSpeedThreshold()
Exit Sub
End If
End If
End While
End Sub
I tried the following, but it never stopped the process when I released the mouse button:
Private Sub btnFaster_Hold(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Mouse
While Control.MouseButtons() = Windows.Forms.MouseButtons
If tbSpeedThreshold.Value < 20 Then
tbSpeedThreshold.Value += 1
System.Threading.Thread.Sl
If Control.MouseButtons. = Windows.Forms.MouseButtons
SetSpeedThreshold()
Exit Sub
End If
End If
End While
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant! Thanks!
Gald I could help and thanks for the grade!
jpaulino
jpaulino
ASKER
No problem and thanks again! It was perfect!
You can use a timer for that.