ContextMenu

  • Thread starter Thread starter Usarian Skiff
  • Start date Start date
U

Usarian Skiff

I have buttons on a form that respond to click events.
I need to implement a context menu for them.
I create the context menu and assign the buttons to it, then create the menu
item and write the code.

Problem is, when I right-click to get the menu, instead it initiates the
Click event.

Any ideas?

Usarian
 
Can you strip down your code to bare minimum, verify that you can reproduce
the problem, and submit the code?

I tried what you described; Assigning a context menu to a button and when I
right click the button, I get the context menu. When I left click the
button I get the button click event.

DalePres
 
My bad,

It's actually a label.

And I found it will appear if I double right click, but it executes the
click event as well, and when the menu pops up, it's under the labels.
 
Try adding an event handler for the ContextMenu.Popup event. In the Popup
event set a flag and if the flag is set, do nothing in your click event.
Here's some sample code:

Private poppingMenu As Boolean = False

Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup

poppingMenu = True

End Sub

Private Sub Label1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Label1.Click

If Not poppingMenu Then

MessageBox.Show("Label1 clicked")

Else

poppingMenu = False

Exit Sub

End If

End Sub
 
Ah! Great thought! Thank you!
Usarian

DalePres said:
Try adding an event handler for the ContextMenu.Popup event. In the Popup
event set a flag and if the flag is set, do nothing in your click event.
Here's some sample code:

Private poppingMenu As Boolean = False

Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ContextMenu1.Popup

poppingMenu = True

End Sub

Private Sub Label1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Label1.Click

If Not poppingMenu Then

MessageBox.Show("Label1 clicked")

Else

poppingMenu = False

Exit Sub

End If

End Sub
 
Back
Top