From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

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

New in 2005r1

Supported for all project types and targets.

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 they 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.AddMenu( New MenuItem("Test 1"))
base.AddMenu( New MenuItem("Test 2"))
base.AddMenu( New MenuItem("Test 3"))

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

// Add a sub menu
Var submenu As New MenuItem("SubMenu")
submenu.AddMenu( New MenuItem("SubMenu Test 1"))
submenu.AddMenu( New MenuItem("SubMenu Test 2"))
submenu.AddMenu( New MenuItem("SubMenu Test 3"))

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

Return True