getting doubleclick on a menu-popping control

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

My control pops a menu (below, not directly under, the pointer) OnMouseDown,
and, probably because of the loss of focus, OnDoubleClick doesn't fire any
more. Is there a way to get doubleclick back without some ugly workaround?

TIA,
Bob
 
Why don't you fix it so that the MouseDown only pops the menu on a right
click? That will allow a left double click to trigger the other event you
desire.

Will that work for you?
 
No, that's not acceptable. This is a button that must function like the menu
icon at the top left-hand corner of a windows form. You left-click it, you
get a menu. You double left-click it, it closes the form.

Bob
 
Well I got something reasonable working...

Bob

------

Public Class UserControl1
Inherits System.Windows.Forms.Control

Private WithEvents DoubleClickTimer As Timer

Public Sub New()
DoubleClickTimer = New Timer
DoubleClickTimer.Interval = 500
Me.ContextMenu = New ContextMenu
Me.ContextMenu.MenuItems.Add("something")
End Sub

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
If ReadyForDoubleClick Then
Me.OnDoubleClick(e)
Else
Me.ContextMenu.Show(Me, New Point(e.X, e.Y + 10))
End If
MyBase.OnMouseDown(e)
End Sub

Protected Overrides Sub OnDoubleClick(ByVal e As System.EventArgs)
ReadyForDoubleClick = False
MsgBox("test")
MyBase.OnDoubleClick(e)
End Sub

Private Property ReadyForDoubleClick() As Boolean
Get
Return Not timerticked
End Get
Set(ByVal Value As Boolean)
timerticked = Not Value
DoubleClickTimer.Enabled = Value
End Set
End Property

Private timerticked As Boolean = True
Private Sub DoubleClickTimer_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) _
Handles DoubleClickTimer.Tick
ReadyForDoubleClick = False
End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case 279 'context menu popup
Me.OnContextMenuPopup(New EventArgs)
Case 287 'menu select
'if the user really selected a menu item, LParam will
contain a value
If Not m.LParam.Equals(System.IntPtr.Zero) Then
ReadyForDoubleClick = False
Case 530 'exit context menu popup
Me.OnContextMenuExit(New EventArgs)
End Select
MyBase.WndProc(m)
End Sub

Private _DoingContextMenu As Boolean
Protected Overridable ReadOnly Property DoingContextMenu() As Boolean
Get
Return _DoingContextMenu
End Get
End Property

Protected Overridable Sub OnContextMenuPopup(ByVal e As EventArgs)
_DoingContextMenu = True
ReadyForDoubleClick = True
End Sub

Protected Overridable Sub OnContextMenuExit(ByVal e As EventArgs)
_DoingContextMenu = False
If ReadyForDoubleClick Then
ReadyForDoubleClick = False
If Me.ContainsCursor Then Me.OnDoubleClick(e)
End If
End Sub

Protected ReadOnly Property ContainsCursor() As Boolean
Get
Return
Me.ClientRectangle.Contains(Me.PointToClient(Me.Cursor.Position))
End Get
End Property

End Class
 
Back
Top