In This Article

Popup Menus

Popup menus, represented by the PopupMenu class, provide pre-defined context menus that can be used in response to events such as right-clicks on controls.

Screenshot

All popup menus should have a unique key and are added to a BarManager via the PopupMenus collection. The popup menu Key is used as an indexer in that collection.

Using the Toolbar Style

By default, popup menus display looking like normal menus. However they can also optionally display using a toolbar style.

To display them using a toolbar style, set the UseToolBarStyle to true. The ToolBarStyledMenuWrapWidth property controls how wide the menu can become before wrapping command links to the next line.

The CommandLinks collection stores all of the command links that are contained by the popup menu. To programmatically add a new command link to the bar control, simply add it to collection.

Showing the Popup Menu

There are several overloads of the Show method that can be used to display the popup menu. Whenever an owner control can be specified for the popup menu, it is best to pass that in the appropriate overload.

Some of the overloads show the popup menu at a specific Point, either in screen or client coordinates (depending on the overload).

This sample demonstrates how to show a popup menu at the screen coordinate 100, 100.

barManager.PopupMenus["ContextPopupMenu"].Show(new Point(100, 100));

The other overloads show the popup menu around a specific Rectangle bounds, either in screen or client coordinates (depending on the overload). These overloads accept parameters indicating from which corner of the Rectangle to fly out the popup menu, and at which orientation from that corner. There also is an offset parameter indicating how far away from the bounds to display the popup menu.

This sample demonstrates how to show a popup menu around the client coordinates of a button. The popup will show vertically downward from the lower left corner.

barManager.PopupMenus["ButtonPopupMenu"].Show(
	button, button.ClientRectangle, Corner.LowerLeft, Orientation.Vertical, 0);

If the popup menu was retrieved from the PopupMenus collection of the BarManager, it will already have the BarManager reference assigned. Otherwise, a BarManager should be set to the popup menu in its constructor when created.

Once a BarManager has been set, the command link clicks can be handled in the BarManager events.