Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Right mouse click menu

hello,
how can I display a menu like the right click menu on internet explorer??
I hope someone can help me out whis this
Thanks
Drew
[169 byte] By [Drew_gable] at [2007-11-11 8:10:35]
# 1 Re: Right mouse click menu
Create a top level menu in the normal way but make it invisible
Then in the form code insert, replacing "menuMenu" with the name of your menu:

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then 'right button
Me.PopupMenu menuMenu, , X, Y
End If
End Sub
zagarat at 2007-11-11 17:25:54 >
# 2 Re: Right mouse click menu
If you don't want to use magic numbers (they are bad practice) you can use this also:

If Button = 2 Then 'right button

Becomes:

If Button = vbRightButton Then
edburdo at 2007-11-11 17:26:54 >
# 3 Re: Right mouse click menu
that works ok, but question:

what if someone already has a menu on the form, how do they add another to be able to do this>? thanks
vchatlive at 2007-11-11 17:27:52 >
# 4 Re: Right mouse click menu
zaqarat,your line,"Then in the form code insert, replacing "menuMenu" with the name of your menu:" is inexplicable.Explain it properly.

The main thing is that below this menu you need to've one or more visible sub-menus(s).
And these menus will appear as the popmenu,as one whole.
softraj at 2007-11-11 17:28:54 >
# 5 Re: Right mouse click menu
well i got the menu to show up only proble is its showing up down by the system tray instead of on the node.. how can i get the menu to show up on the node that is selected? thanks!
vchatlive at 2007-11-11 17:29:53 >
# 6 Re: Right mouse click menu
Are you using the PopupMenu code from above?

If so, you might need to twiddle the X and Y values.

Some controls report X, Y based on the top of the FORM. Some report X,Y from the top of the CONTROL. Others report X,Y from the top of the SCREEN.

So you need to check the X,Y coords and see what they are based on. Then adjust them to get the right values.
edburdo at 2007-11-11 17:30:52 >
# 7 Re: Right mouse click menu
Or else if you only want the menu to pop up where you 'right-moused', leave out the X & Y from your popmenu.

P.S. Softraj - zaqarat,your line,"Then in the form code insert, replacing "menuMenu" with the name of your menu:" is inexplicable.Explain it properly. - presumably means use 'whatever is the name of your menu' should be inserted instead of 'menuMenu', as per normal postings on this forum ;-)
gupex at 2007-11-11 17:31:56 >