From Xojo Documentation
Jump to: navigation, search

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

New in 2005r1

This event is called when it is appropriate to display a contextual menu for the control.


This event handler 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. Depending on platform, it might be in the MouseUp or MouseDown event and it might be a right+click or by pressing the contextual menu key on the keyboard, for example.

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 following section.


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"))

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

Return True
Personal tools

Starting Out
Dig Deeper
More Help