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:
Public Class Form1 Private WithEvents MouseDownTimer As New Timer Private WithEvents HoldActiontimer As New Timer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler MouseDownTimer.Tick, AddressOf MouseDownTimer_Tick AddHandler HoldActiontimer.Tick, AddressOf HoldActiontimer_Tick 'set the MouseDownTimer.Interval for the time until the action BEGINS to occur 'set the HoldActionTimer.Interval for the time between actions that occur AFTER the hold peroid expires Me.MouseDownTimer.Interval = 1000 Me.HoldActionTimer.Interval = 100 End Sub Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown Me.MouseDownTimer.Start() End Sub Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp 'the mouse is up... stop all of the timers Me.MouseDownTimer.Stop() Me.HoldActionTimer.Stop() End Sub Private Sub MouseDownTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Me.HoldActiontimer.Start() End Sub Private Sub HoldActiontimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Call MouseHoldAction() End Sub Private Sub MouseHoldAction() Static i As Integer i += 1 Me.Label1.Text = i.ToString End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End Sub End Class




Reply With Quote