hey all. this has probably been answered already, but i couldn't find it. how can i add a right click menu to an object in my form? i.e. if the user right clicks a go button, it gives a menu saying "open in new window" "open in this window" etc.
Printable View
hey all. this has probably been answered already, but i couldn't find it. how can i add a right click menu to an object in my form? i.e. if the user right clicks a go button, it gives a menu saying "open in new window" "open in this window" etc.
Use the mouse_down and up event. Both of them allow you test which mousebutton has been pressed. So set either the mouse_down or mouse_up on the button to check if the right button was pressed and then pop up the menu.
could you provide an example code? i'm also not sure how to pop up the menu. i want it to look like the normal right click menus.
You would use the PopupMenu method. Yeah I know real hard right. :D Basically build your menu normally as you would build one in the menu editor, set it to Visible = False, then use Me.Popupmenu to pop it up (you will need to use the X and Y params to position it.
This is taken directly from help and assumes you have a menu already set up on your form.
Code:Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ' Check if right mouse button
' was clicked.
PopupMenu mnuFile ' Display the File menu as a
' pop-up menu.
End If
End Sub
ah i see. thank you so much! also, i know they're noob questions :P, but 1) how do i find the X and Y position of the mouse, and 2) how do i determine which mouse button was pressed?
now i know how to see which mouse button was pressed ^_^
There passed as integer values when the mouse_up event occurs.
how would i access these?
OHHHHH nevermind. thank you everyone!! i got it now. big kudos to veritas and danecook
Their basic methods available to most controls. Easiest way would be to go to view code then select the control from the left drop down menu and then find "Mouse Up" from the right drop down menu.
If you would be so kind as to mark this as resolved?