Popup Menu On Right Click

R

Randy

I am trying to right click on a form and have a custom
popup menu display. Does anyone know how to do this in
vb.net.

Thanks!
 
P

Philip Rieck

Drag a "ContextMenu" control onto your form in the designer, and edit it
like you would a menu (add items, etc). Then in your form, you can show it
like this:

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(Me, New Point(e.X, e.Y))
End If
End Sub
 
H

Herfried K. Wagner [MVP]

* "Philip Rieck said:
Drag a "ContextMenu" control onto your form in the designer, and edit it
like you would a menu (add items, etc). Then in your form, you can show it
like this:

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(Me, New Point(e.X, e.Y))
End If
End Sub

Why not assign the context menu to the form's 'ContextMenu' property?
 
P

Philip Rieck

Herfried, you're right - ContextMenu would probably be better.

I'm so used to answering "when showing context menu, show x if
somecondition, else y", so I have this snippet (well, the snippit I based
this on) around for a quick answer. I also have one that sets the
contextmenu property of the form and reacts to the popup event to
enable/disable menu items - should have used and edited that one. Sorry for
any confusion.
 

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