Window.ConstructContextualMenu
From Xojo Documentation
Supported for all project types and targets.
Fires whenever it is appropriate to display a contextual menu for the window.
Notes
This is the recommended way to handle contextual menus because this event figures out whether the user has requested the contextual menu, regardless of how he did it. Returns a Boolean. Base is analogous to the menu bar for the contextual menu. Any items you add to Base will be shown as menu items. If you return False, the event is passed up the parent hierarchy. If you return True, the contextual menu is displayed. The parameters x and y are the mouse locations. If the event was fired because of a non-mouse event, then x and y are both set to -1. See the example of a contextual menu in the examples for the RectControl class.
Example
The following ConstructContextualMenu event handler builds a menu with three menu items plus a submenu with three additional menu items.
base.Add(New MenuItem("Test 1" )
base.Add(New MenuItem("Test 2"))
base.Add(New MenuItem("Test 3"))
// Add a Separator
base.Add(New MenuItem(MenuItem.TextSeparator))
// Add a sub menu
Var submenu As New MenuItem("SubMenu")
submenu.Add(New MenuItem("SubMenu Test 1"))
submenu.Add(New MenuItem("SubMenu Test 2"))
submenu.Add(New MenuItem("SubMenu Test 3"))
base.Add(submenu)
// Add a Separator
base.Add(New MenuItem(MenuItem.TextSeparator))
// Add an item that's on a menu bar so that you can see you don't
// have to handle every item returned.
base.Add(UntitledItem)
#If TargetMacOS Then
// because of how quitting the app is handled on Mac OS you cannot add the FileQuit item on OS X
#Else
base.Add(FileQuit)
#Endif
Return True
See Also
The RectControl.ConstructContextualMenu event handler for creating contextual menus in controls.