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
Visual Basic.NET

Avatar of undefined
Last Comment
indy500fan

8/22/2022 - Mon
Jorge Paulino

Hi indy500fan,

You can use a timer for that.
ASKER CERTIFIED SOLUTION
Jorge Paulino

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
indy500fan

ASKER
Brilliant!  Thanks!
Jorge Paulino

Gald I could help and thanks for the grade!

jpaulino
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
indy500fan

ASKER
No problem and thanks again!  It was perfect!