Link to home
Start Free TrialLog in
Avatar of indy500fan
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.MouseEventArgs) Handles btnFaster.MouseDown
        While Control.MouseButtons() = Windows.Forms.MouseButtons.Left
            If tbSpeedThreshold.Value < 20 Then
                tbSpeedThreshold.Value += 1

                System.Threading.Thread.Sleep(500)
                If Control.MouseButtons. = Windows.Forms.MouseButtons.None Then
                    SetSpeedThreshold()
                    Exit Sub
                End If
            End If
        End While
    End Sub
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Hi indy500fan,

You can use a timer for that.
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of indy500fan
indy500fan

ASKER

Brilliant!  Thanks!
Gald I could help and thanks for the grade!

jpaulino
No problem and thanks again!  It was perfect!