We help IT Professionals succeed at work.

How do I have a button repeat an action for as long as I have the button depressed?

indy500fan
indy500fan asked
on
256 Views
Last Modified: 2010-04-23
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
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Hi indy500fan,

You can use a timer for that.
IT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Brilliant!  Thanks!
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Gald I could help and thanks for the grade!

jpaulino

Author

Commented:
No problem and thanks again!  It was perfect!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.