Show / Hide Table of Contents

Class popupMenu

Popup menu.

public class popupMenu : MTBase
Remarks

Can be used everywhere: in automation scripts, WPF apps, other apps, etc. Also can be used as a popup list and supports many items with scrollbar.

Menu item text can include hotkey after '\t' character and/or tooltip after '|' or '\0' character. Examples: "Text\t Hotkey", "Text|Tooltip", "Text\t Hotkey\0 Tooltip". Character with prefix & (eg 'A' in "Save &As") will be underlined (depends on Windows settings and PMFlags) and can be used to select the item with keyboard.

Keyboard, mouse:

  • Enter, Tab, Space - close the menu and execute the focused item. Or show the submenu.
  • Esc - close the menu or current submenu.
  • Left - close current submenu.
  • Right - open submenu.
  • Down, Up, PageDown, PageUp, End, Home - focus other item.
  • underlined menu item character - close the menu and execute the item. Or show the submenu. See PMFlags.Underline.
  • Alt, Win, F10, Apps, Back - close menus.
  • click outside - close the menu.
  • middle click - close the menu.
  • right click - show context menu (if used constructor with parameters).

While a menu is open, it captures many keyboard keys, even when its thread isn't the foreground thread.

Not thread-safe. All functions must be called in same thread, unless documented otherwise.

Examples
var m = new popupMenu("example");
m["One"] = o => print.it(o);
m["Two\0Tooltip", image: icon.stock(StockIcon.DELETE)] = o => { print.it(o); dialog.show(o.ToString()); };
m.Submenu("Submenu", m => {
	m["Three"] = o => print.it(o);
	m["Four"] = o => print.it(o);
});
m["notepad"] = o => run.itSafe(folders.System + "notepad.exe");
m.Show();

Namespace: Au
Assembly: Au.dll
Inheritance
object
MTBase
popupMenu
Inherited Members
MTBase.ExtractIconPathFromCode
MTBase.ActionThread
MTBase.ActionException
MTBase.PathInTooltip
MTBase.ImageSize

Constructors

Name Description
popupMenu()

Use this constructor for various context menus of your app.

popupMenu(string, string, int)

Use this constructor in scripts.

Properties

Name Description
CheckDontClose

Don't close menu when clicked a checkbox or radio item. This property is applied to items added afterwards; submenus inherit it.

FocusedItem

Gets or sets the focused menu item.

Font

Sets or gets font.

IsOpen

Returns true if the menu window is open.

this[string, MTImage, bool, int, string]

Adds menu item with action (callback function) that is executed on click.

Items

Gets added items, except separators and items in submenus.

ItemsAndSeparators

Gets added items and separators, except items in submenus.

KeyboardHook

Gets or sets callback function that decides how to respond to pressed keys (default, close, ignore, block).

Last

Gets the last added menu item.

Metrics

Sets some metrics, for example item padding.

RawText

Don't use: & character for keyboard shortcut; tab character for hotkey; | character for tooltip (but use \0). This property is applied to items added afterwards; submenus inherit it.

Result

After closing the menu gets the selected item, or null if canceled.

caretRectFunc

Sets a user-defined "get caret rectangle" function.

defaultFont

Sets or gets default font.

defaultMetrics

Sets or gets default metrics.

Methods

Name Description
Add(int, string, MTImage, bool, int, string)

Adds menu item with explicitly specified id.

Add(string, MTImage, bool, int, string)

Adds menu item with auto-generated id.

Add(string, Action<PMItem>, MTImage, bool, int, string)

Adds menu item with action (callback function) that is executed on click.

AddCheck(string, bool, Action<PMItem>, bool, MTImage, int, string)

Adds menu item to be used as a checkbox.

AddRadio(string, bool, Action<PMItem>, bool, MTImage, int, string)

Adds menu item to be used as a radio button in a group of such items.

Close(bool)

Closes the menu and its submenus.

Separator()

Adds separator.

Show(PMFlags, POINT?, RECT?, AnyWnd)

Shows the menu and waits until closed.

Submenu(string, Action<popupMenu>, MTImage, bool, int, string)

Adds menu item that opens a submenu. Used like m.Submenu("Example", m => { /* add submenu items */ });.

Submenu(string, Func<popupMenu>, MTImage, bool, int, string)

Adds menu item that opens a reusable submenu.

showSimple(Strings, PMFlags, POINT?, RECT?, AnyWnd)

Creates and shows a simple popup menu. Without images, actions, submenus. Returns item id or 0.