A Menu object lets you create and display a popup menu. Menus can appear anywhere on your dialog (or anywhere on screen), and they can also appear attached to certain dialog controls (e.g. a dropdown button, or over a specific listview item).
You create an initial Menu object via the Dialog.CreateMenu() method. Once you have the root menu object you can add items and sub-menus to it. The AddSubMenu method returns another Menu object, which lets you configure the contents of the sub-menu.
Menus contain items of different types - each item is represented by a MenuItem object. The item types are:
Use the Show menu to display your menu once you have configured it.
| Method Name | Arguments | Return Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AddItem |
label |
Adds a new item to the menu and returns a MenuItem object that represents it. All arguments are optional - you can configure the menu item via its properties after creating it if you want. As well as this method you can use the specialised methods AddSeparator, AddSubMenu and AddToggle to add particular types of items.
|
|||||||||||||||||
AddRadioGroup |
id |
none |
Defines a "radio group", a set of two or more mutually exclusive toggle items. When an item in a radio group is chosen, it appears selected, and the previously selected item in the group is automatically deselected. The id values must be the same as those provided when the menu items were added. |
||||||||||||||||
AddSeparator |
position |
Adds a new separator item to the menu. If position is not provided the separator is added to the end. |
|||||||||||||||||
AddSubMenu |
label |
Adds a new sub-menu item to the menu. All arguments are optional - you can configure the menu item via its properties after creating it if you want.
|
|||||||||||||||||
AddToggle |
label |
Adds a new toggle item to the menu. All arguments are optional - you can configure the menu item via its properties after creating it if you want.
|
|||||||||||||||||
FindItem |
id |
Locates a menu item either by ID, position or label, and returns the MenuItem object representing it. By default, id specifies the ID provided when the menu item was added. If you set the optional by_position argument to true the id value is interpreted as a position (e.g. FindItem(3, true) would return the fourth item in the menu. You can also locate an item by its label, by passing a string as the argument. Standard wildcard patterns are supported. |
|||||||||||||||||
RemoveItem |
id |
bool |
Removes a menu item from the menu, either by ID, position or label. By default, id specifies the ID provided when the menu item was added. If you set the optional by_position argument to true the id value is interpreted as a position (e.g. RemoveItem(3, true) would remove the fourth item in the menu. You can also remove an item by its label, by passing a string as the argument. Standard wildcard patterns are supported - only the first matching item will be removed. The method returns true if the item was successfully removed. |
||||||||||||||||
Show |
int or |
Displays the popup menu. You can show the menu in three ways:
To display the menu on a dialog, pass the appropriate Dialog object and either the name of a control or x,y coordinates relative to the top-left corner of the dialog's client area. If a control is specified the menu will appear positioned over that control. Special handling exists for button controls - the menu will appear positioned below it, like a drop-down menu button. For other controls the menu will appear at the mouse coordinates if the mouse is currently over that control (this lets you add right-click functionality). The optional flags are:
The "support scroll" option substitutes an Opus menu for a standard Windows one, which supports showing a scrollbar for long lists. However this does not support multi-select mode. |