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

BarManager.SetPopupContextMenu(Control, PopupMenuBase) Method

Sets the popup menu for a control within a form.

Namespace: DevExpress.XtraBars

Assembly: DevExpress.XtraBars.v18.2.dll

Declaration

public void SetPopupContextMenu(
    Control control,
    PopupMenuBase menu
)

Parameters

Name Type Description
control Control

The control which the popup menu should be assigned to.

menu PopupMenuBase

The popup menu to set.

Remarks

See the BarManager.GetPopupContextMenu topic for more information.

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");
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetPopupContextMenu(Control, PopupMenuBase) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also