Hi,
I just found a post on Google's archive for this newsgroup, from William
Ryan:
"I'm not sure what you want to do ulitmately, but you can trap MouseDown
and MouseUp. YOu can start a timer for instance and after X intervals,
do whatever you are trying to accomplish - just make sure you stop the
timer on MouseUp."
William, have you actually tried this? What you're suggesting is exactly
what I'm doing, but it simply doesn't work!
Version 1, try overriding OnMouseDown and OnMouseUp:
-----
Imports System.Windows.Forms
Public Class RepeatButton
Inherits Button
Private WithEvents mTimer As Timer
Public Sub New()
mTimer = New Timer
mTimer.Enabled = False
mTimer.Interval = 250
End Sub
Public Property Interval() As Integer
Get
Return mTimer.Interval
End Get
Set(ByVal Value As Integer)
mTimer.Interval = Value
End Set
End Property
Private Sub OnTimer(ByVal sender As Object, ByVal e As EventArgs)
Handles mTimer.Tick
OnClick(EventArgs.Empty)
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
mTimer.Enabled = True
MyBase.OnMouseDown(e)
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As
System.Windows.Forms.MouseEventArgs)
mTimer.Enabled = False
MyBase.OnMouseUp(e)
End Sub
End Class
-----
Version 2, try handling the MouseDown and MouseUp events:
-----
Imports System.Windows.Forms
Public Class RepeatButton
Inherits Button
Private WithEvents mTimer As Timer
Public Sub New()
mTimer = New Timer
mTimer.Enabled = False
mTimer.Interval = 250
End Sub
Public Property Interval() As Integer
Get
Return mTimer.Interval
End Get
Set(ByVal Value As Integer)
mTimer.Interval = Value
End Set
End Property
Private Sub OnTimer(ByVal sender As Object, ByVal e As EventArgs)
Handles mTimer.Tick
OnClick(EventArgs.Empty)
End Sub
Private Sub RepeatButton_MouseDown(ByVal sender As Object, ByVal e
As MouseEventArgs) Handles MyBase.MouseDown
mTimer.Enabled = True
End Sub
Private Sub RepeatButton_MouseUp(ByVal sender As Object, ByVal e As
MouseEventArgs) Handles MyBase.MouseUp
mTimer.Enabled = False
End Sub
End Class
-----
Regards,
Elisa