Results 1 to 3 of 3

Thread: <renamed> Click and Hold Control

Threaded View

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    <renamed> Click and Hold Control

    I put this together because I have a constant need to click a button and repeat its action of it has been held down for a while....

    my share to you....Happy Thanks Merry Valentines Day

    cut and paste into a new project...
    vb Code:
    1. Public Class Form1
    2.  
    3.     Private WithEvents MouseDownTimer As New Timer
    4.     Private WithEvents HoldActiontimer As New Timer
    5.  
    6.  
    7.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    8.  
    9.  
    10.         AddHandler MouseDownTimer.Tick, AddressOf MouseDownTimer_Tick
    11.         AddHandler HoldActiontimer.Tick, AddressOf HoldActiontimer_Tick
    12.  
    13.  
    14.         'set the MouseDownTimer.Interval for the time until the action BEGINS to occur
    15.         'set the HoldActionTimer.Interval for the time between actions that occur AFTER the hold peroid expires
    16.         Me.MouseDownTimer.Interval = 1000
    17.         Me.HoldActionTimer.Interval = 100
    18.  
    19.     End Sub
    20.  
    21.     Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
    22.         Me.MouseDownTimer.Start()
    23.     End Sub
    24.  
    25.     Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
    26.         'the mouse is up... stop all of the timers
    27.         Me.MouseDownTimer.Stop()
    28.         Me.HoldActionTimer.Stop()
    29.     End Sub
    30.  
    31.     Private Sub MouseDownTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    32.         Me.HoldActiontimer.Start()
    33.     End Sub
    34.  
    35.     Private Sub HoldActiontimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    36.         Call MouseHoldAction()
    37.     End Sub
    38.  
    39.     Private Sub MouseHoldAction()
    40.         Static i As Integer
    41.         i += 1
    42.         Me.Label1.Text = i.ToString
    43.     End Sub
    44.  
    45.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    46.  
    47.     End Sub
    48. End Class
    Last edited by kebo; Dec 5th, 2008 at 02:32 PM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width