Window.ConstructContextualMenu

From Xojo Documentation

Event


Window.ConstructContextualMenu(Base as MenuItem,x as Integer, y as Integer) As Boolean

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.

// Add some items
base.Append(New MenuItem("Test 1" )
base.Append(New MenuItem("Test 2"))
base.Append(New MenuItem("Test 3"))

// Add a Separator
base.Append(New MenuItem(MenuItem.TextSeparator))

// Add a sub menu
Dim submenu As New MenuItem("SubMenu")
submenu.Append(New MenuItem("SubMenu Test 1"))
submenu.Append(New MenuItem("SubMenu Test 2"))
submenu.Append(New MenuItem("SubMenu Test 3"))
base.Append(submenu)

// Add a Separator
base.Append(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.Append(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.Append(FileQuit)
#Endif

Return True

See Also

The RectControl.ConstructContextualMenu event handler for creating contextual menus in controls.