DXPopupMenu Class

A base class for popup menus in DevExpress .NET controls.

Namespace: DevExpress.Utils.Menu

Assembly: DevExpress.Utils.v20.1.dll

Declaration

public class DXPopupMenu :
    DXSubMenuItem,
    IDXDropDownControl,
    IOptionsMultiColumnOwner
Public Class DXPopupMenu
    Inherits DXSubMenuItem
    Implements IDXDropDownControl,
               IOptionsMultiColumnOwner

Related API Members

The following members accept/return DXPopupMenu objects:

Remarks

Many DevExpress .NET controls provide support for context menus. They provide built-in context menus for various visual elements and allow you to create custom menus or extend existing ones. Menus in these controls are represented by the DXPopupMenu class descendants. Menu items are represented by the DXMenuItem, DXMenuCheckItem, DXSubMenuItem, DXButtonGroupItem and DXEditMenuItem objects.

A DXPopupMenu can be displayed as a regular menu, popup bar or RibbonMiniToolbar. To specify the menu's display mode, use the DXPopupMenu.MenuViewType property. To display the menu, use the DXPopupMenu.ShowPopup or IDXDropDownControl.Show methods.

Example 1


// Display a DXPopupMenu as a regular menu
UserLookAndFeel lf = UserLookAndFeel.Default;
Control parentControl = this;
Point pt;
DXPopupMenu dxPopupMenu = new DXPopupMenu();
//...
dxPopupMenu.MenuViewType = MenuViewType.Menu;
dxPopupMenu.ShowPopup(parentControl, pt);
//or
((IDXDropDownControl)dxPopupMenu).Show(new SkinMenuManager(lf), parentControl, pt);

Example 2


// Display a DXPopupMenu as a popup bar
Control parentControl = this;
Point pt;
DXPopupMenu dxPopupMenu = new DXPopupMenu();
//...
dxPopupMenu.MenuViewType = MenuViewType.Toolbar;
dxPopupMenu.ShowPopup(parentControl, pt);
//or
((IDXDropDownControl)dxPopupMenu).Show(barManager1, parentControl, pt);

Example 3


// Display a DXPopupMenu as a RibbonMiniToolbar
Control parentControl = this;
Point pt;
DXPopupMenu dxPopupMenu = new DXPopupMenu();
//...
dxPopupMenu.MenuViewType = MenuViewType.RibbonMiniToolbar;
dxPopupMenu.ShowPopup(parentControl, pt);
//or
((IDXDropDownControl)dxPopupMenu).Show(RibbonControl1, parentControl, pt);

Examples

This example shows how to display DXPopupMenu as a regular menu, popup bar or RibbonMiniToolbar. To change a menu's display mode, the MenuViewType property is used.To display DXPopupMenu as a popup bar, you need to set the MenuViewType property to Toolbar and also pass a BarManager object to the DXPopupMenu.Show method. Similarly, to display DXPopupMenu as RibbonMiniToolbar, you need to set the MenuViewType property to Toolbar and also pass a RibbonControl object to the DXPopupMenu.Show method.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors.Repository;

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

            InitPopupMenu();
        }

        protected virtual void InitPopupMenu() {
            RepositoryItemComboBox riEditComboBox = new RepositoryItemComboBox();
            riEditComboBox.Items.Add("item1");
            riEditComboBox.Items.Add("item2");
            riEditComboBox.Items.Add("item3");
            riEditComboBox.Items.Add("item4");
            riEditComboBox.Items.Add("item5");

            RepositoryItemDateEdit riDateEdit = new RepositoryItemDateEdit();

            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem("Cut", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Cut_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Cut_32x32, null));
            menu.Items.Add(new DXMenuItem("Copy", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Copy_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Copy_32x32, null));
            menu.Items.Add(new DXMenuItem("Paste", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Paste_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Paste_32x32, null));
            menu.Items.Add(new DXEditMenuItem("ComboBox", riEditComboBox, null, null, null, 100, -1));
            menu.Items.Add(new DXEditMenuItem("DateEdit", riDateEdit, null, null, null, 100, -1));
            DXButtonGroupItem group1 = new DXButtonGroupItem();
            group1.Caption = "Button Group 1";
            group1.Items.Add(new DXMenuItem("Open", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Open_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Open_32x32, null));
            group1.Items.Add(new DXMenuItem("Save", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Save_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Save_32x32, null));
            group1.Items.Add(new DXMenuItem("Save All", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.SaveAll_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.SaveAll_32x32, null));
            DXButtonGroupItem group2 = new DXButtonGroupItem();
            group2.Caption = "Button Group 2";
            group2.Items.Add(new DXMenuItem("Edit", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Edit_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Edit_32x32, null));
            group2.Items.Add(new DXMenuItem("Delete", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Delete_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Delete_32x32, null));
            group2.Items.Add(new DXMenuItem("Print", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Print_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Print_32x32, null));
            DXButtonGroupItem group3 = new DXButtonGroupItem();
            group3.Caption = "Button Group 3";
            group3.Items.Add(new DXMenuItem("Close", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Close_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Close_32x32, null));
            group3.Items.Add(new DXMenuItem("Delete", new EventHandler(OnItemClick), DXPopupMenu_DisplayMode.Properties.Resources.Delete_16x16, null, DXPopupMenu_DisplayMode.Properties.Resources.Delete_32x32, null));
            menu.Items.Add(group1);
            menu.Items.Add(group2);
            menu.Items.Add(group3);
        }
        void OnItemClick(object sender, EventArgs e) { }

        DXPopupMenu menu;
        private void btnDisplayAsRegularMenu_Click(object sender, EventArgs e) {
            SimpleForm form = new SimpleForm();
            form.PopupMenu = menu;
            form.Show();
        }
        private void btnDisplayAsPopupBar_Click(object sender, EventArgs e) {
            BarsForm form = new BarsForm();
            form.PopupMenu = menu;
            form.Show();
        }
        private void btnDisplayAsRibbonMiniToolbar_Click(object sender, EventArgs e) {
            RibbonForm1 form = new RibbonForm1();
            form.PopupMenu = menu;
            form.Show();
        }
    }
}

Implements

See Also