Skip to main content
A newer version of this page is available. .
Bar

PopupMenu Class

The popup menu, managed by a BarManager or RibbonControl.

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v19.2.dll

Declaration

[ToolboxBitmap(typeof(ToolboxIconsRootNS), "PopupMenu")]
public class PopupMenu :
    PopupMenuBase,
    IHasRibbonKeyTipManager,
    PopupControl,
    IDXDropDownControlEx,
    IDXDropDownControl,
    IAppearanceOwner,
    IOptionsMultiColumnOwner

Remarks

The PopupMenu can be used to provide easy access to frequently used commands for a specific control. When associated with an object, the popup menu is opened by right-clicking the object. The popup menu can also be displayed in code, using the PopupMenu.ShowPopup method.

Active Popup

The PopupMenu needs to be associated with a BarManager or RibbonControl. If your project does not contain these components, add one of them to the form. At design time, the PopupMenu is automatically associated with a BarManager or RibbonControl if they are present on the form. When creating a PopupMenu in code, ensure that the PopupMenuBase.Manager or PopupMenuBase.Ribbon property refers to an existing BarManager or RibbonControl component.

Design-Time Menu Customization

At design time, the PopupMenu can be customized by clicking the menu’s smart tag and selecting Run Designer.

PopupMenu-SmartTag-RunDesigner

A click on this link opens the Popup Menu Editor (different editors are used when the menu is associated with the BarManager and RibbonControl).

If the PopupMenu is associated with the BarManager, the Bar Manager’s Customization window and a standalone Popup Menu Editor are invoked.

Popup Menu Customization From

You can customize the menu in a number of ways.

  • Dragging commands from the Customization window to the Popup Menu Editor.
  • Clicking the [Add] button in the Popup Menu Editor.
  • Using a context menu provided by the popup menu’s items.
  • Selecting the popup menu’s item and changing its settings in the Visual Studio Properties grid.

If the PopupMenu is associated with a RibbonControl, the Sub Menus and Popup Menus page of the Ribbon Control’s Designer is opened, providing menu customization tools.

PopupMenu-RibbonControl-Designer-PopupMenuCustomizationPage

The designer allows you to customize the menu by:

  • Dragging commands from the command list (displayed in the center).
  • Clicking the [Add] button displayed below all popup menu items.
  • Selecting the popup menu’s item and changing its settings in the Properties grid.

Items in popup menus are represented by bar item objects. The PopupMenu supports the display of any bar item that is provided by the DevExpress Ribbon, Menu and Docking Library: buttons, sub-menus, editors, static text, etc. For more information, see the Bar Item Links and The List of Bar Items and Links topics.

To populate a popup menu with items in code, add a specific bar item (a BarItem descendant) to the PopupMenuBase.ItemLinks collection.

You can use the BarManager.PopupShowMode and RibbonControl.PopupShowMode properties to specify how popup menus display their sub-menus. Sub-menus can be displayed in the traditional cascaded style as shown in the figure below.

PopupShowMode_Cascaded

Another option is to display sub-menus in-place of their parent popup menus. In this mode, when an end-user hovers over a sub-menu button with the mouse pointer, the currently opened menu hides and in its place, the required sub-menu is displayed. This mode is more convenient for application designed for tablet devices, as it allows you to save valuable screen space. The figure below shows how the sub-menu is displayed in the in-place mode.

PopupShowMode_InPlace1

PopupShowMode_InPlace2

If the in-place mode is enabled, sub-menus can display navigation headers that allow an end-user to navigate backward. See the PopupMenu.ShowNavigationHeader setting for details.

By default, sub-menus are displayed in the traditional cascaded way when managed by the BarManager component and in all styles of the RibbonControl control, except for the TabletOffice and OfficeUniversal styles. In these styles, sub-menus are displayed in the in-place mode by default.

Associating Menu with Controls

An existing PopupMenus can be assigned to the BarButtonItem.DropDownControl or DropDownButton.DropDownControl property. In this instance, the PopupMenu appears when an appropriate BarButtonItem or DropDownButton‘s drop-down arrow is clicked.

When a BarManager or RibbonControl is present on the form, all controls publish the PopupContextMenu property at design time (its caption in the Properties window looks like ‘PopupContextMenu on barManager1’ or ‘PopupContextMenu on ribbonControl1’). You can use this property to assign a PopupMenu to this control. This menu will then be displayed when right-clicking on the control at runtime.

Bars3_ExternalContextMenu

To assign a PopupMenu to a control in code, use the BarManager.SetPopupContextMenu method.

Note

Specific complex controls such as the Grid Control and Tree List do not publish the PopupContextMenu property, as these controls support different context menus for different visual elements. See the help documentation on these products, to learn how to work with context menus in these controls.

Example

This example creates a PopupMenu with three items and binds this menu to the form. You can right-click the form at runtime to invoke the menu.

using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PopupMenu {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Finish BarManager initialization (to allow its further customization on the form load)
            barManager1.ForceInitialize();

            DevExpress.XtraBars.PopupMenu menu = new DevExpress.XtraBars.PopupMenu();
            menu.Manager = barManager1;
            barManager1.Images = imageCollection1;
            BarButtonItem itemCopy = new BarButtonItem(barManager1, "Copy", 0);
            BarButtonItem itemPaste = new BarButtonItem(barManager1, "Paste", 1);
            BarButtonItem itemRefresh = new BarButtonItem(barManager1, "Refresh", 2);
            menu.AddItems(new BarItem[] { itemCopy, itemPaste, itemRefresh });
            // Create a separator before the Refresh item.
            itemRefresh.Links[0].BeginGroup = true;
            // Process item clicks.
            barManager1.ItemClick += BarManager1_ItemClick;
            // Associate the popup menu with the form.
            barManager1.SetPopupContextMenu(this, menu);
        }

        private void BarManager1_ItemClick(object sender, ItemClickEventArgs e) {
            XtraMessageBox.Show(e.Item.Caption + " item clicked");
        }
    }
}

Example

The following code displays a specific PopupMenu if the right mouse button is pressed:

private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
    if(e.Button == MouseButtons.Right)
        popupMenu1.ShowPopup(Control.MousePosition);
}

Implements

See Also