ContextMenu

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
 
D

DalePres

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
 
U

Usarian Skiff

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.
 
D

DalePres

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
 
U

Usarian Skiff

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
 

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

Similar Threads


Top