Button control and MouseDown/MouseUp events

E

Elisa

Hi,

Is it just me or does a Button control completely ignore the MouseDown
and MouseUp events??? I tried adding a handler for each event, but it
looks as if these handlers are never called...


Regards,

Elisa
 
E

Elisa

Hi Franky,

The URL below seems to point to something about a DataGrid.

I'm just trying to intercept the MouseDown and MouseUp events of a plain
old Button control. I even found some example source code on the web
that does much the same as I want to do, but it simply doesn't work. No
matter if I attach an event handler or overwrite the OnMouseDown or
OnMouseUp methods, it simply doesn't work. Another "feature" of the .NET
CF SP2???


Regards,

Elisa

----------
 
E

Elisa

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top