windowsforms-devexpress-dot-xtrabars-dot-barmanager-dot-setpopupcontextmenu-x28-system-dot-windows-dot-forms-dot-control-devexpress-dot-xtrabars-dot-popupmenubase-x29.md
Sets the popup menu for a control within a form.
Namespace : DevExpress.XtraBars
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
public void SetPopupContextMenu(
Control control,
PopupMenuBase menu
)
Public Sub SetPopupContextMenu(
control As Control,
menu As PopupMenuBase
)
| Name | Type | Description |
|---|---|---|
| control | Control |
The control which the popup menu should be assigned to.
| | menu | PopupMenuBase |
The popup menu to set.
|
See the BarManager.GetPopupContextMenu topic for more information.
Before you begin:
The following example demonstrates how to create a popup menu and bind the menu to the Form. Right-click the form to invoke the menu (at runtime).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
namespace DevExpressPopupMenu {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Completes the BarManager's initialization (to allow its further customization on the form load)
barManager1.ForceInitialize();
// Creates a popup menu.
PopupMenu menu = new PopupMenu();
menu.Manager = barManager1;
// Specifies a collection of vector (SVG) icons.
barManager1.Images = svgImageCollection1;
// Creates and initializes the items.
BarSubItem itemAdd = new BarSubItem(barManager1, "Add");
BarButtonItem itemAddFile = new BarButtonItem(barManager1, "File", 2);
BarButtonItem itemAddFolder = new BarButtonItem(barManager1, "Folder", 3);
itemAdd.AddItems(new BarItem[] { itemAddFile, itemAddFolder });
BarButtonItem itemCopy = new BarButtonItem(barManager1, "Copy", 0);
BarButtonItem itemPaste = new BarButtonItem(barManager1, "Paste", 1);
// Adds the items to the popup menu.
menu.AddItems(new BarItem[] { itemAdd, itemCopy, itemPaste });
// Creates a separator before the Copy item.
itemCopy.Links[0].BeginGroup = true;
// Attaches the popup menu to the form.
barManager1.SetPopupContextMenu(this, menu);
// Subscribes to the 'ItemClick' event handler to process item clicks.
barManager1.ItemClick += BarManager1_ItemClick;
}
void BarManager1_ItemClick(object sender, ItemClickEventArgs e) {
XtraMessageBox.Show(string.Format("The '{0}' item was clicked.", e.Item.Caption));
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraBars
Imports DevExpress.XtraEditors
Namespace DevExpressPopupMenu
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Completes the BarManager's initialization (to allow its further customization on the form load)
barManager1.ForceInitialize()
' Creates a popup menu.
Dim menu As New PopupMenu()
menu.Manager = barManager1
' Specifies a collection of vector (SVG) icons.
barManager1.Images = svgImageCollection1
' Creates and initializes the items.
Dim itemAdd As New BarSubItem(barManager1, "Add")
Dim itemAddFile As New BarButtonItem(barManager1, "File", 2)
Dim itemAddFolder As New BarButtonItem(barManager1, "Folder", 3)
itemAdd.AddItems(New BarItem() { itemAddFile, itemAddFolder })
Dim itemCopy As New BarButtonItem(barManager1, "Copy", 0)
Dim itemPaste As New BarButtonItem(barManager1, "Paste", 1)
' Adds the items to the popup menu.
menu.AddItems(New BarItem() { itemAdd, itemCopy, itemPaste })
' Creates a separator before the Copy item.
itemCopy.Links(0).BeginGroup = True
' Attaches the popup menu to the form.
barManager1.SetPopupContextMenu(Me, menu)
' Subscribes to the 'ItemClick' event handler to process item clicks.
AddHandler barManager1.ItemClick, AddressOf BarManager1_ItemClick
End Sub
Private Sub BarManager1_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
XtraMessageBox.Show(String.Format("The '{0}' item was clicked.", e.Item.Caption))
End Sub
End Class
End Namespace
The image below shows the result.
The following code snippet (auto-collected from DevExpress Examples) contains a reference 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.
winforms-spreadsheet-spell-check-cell-text/CS/SpreadsheetSpellchecking/Form1.cs#L31
if (!e.IsCustom) {
BarManager.SetPopupContextMenu(e.Editor, popupMenu);
spellChecker.Check(e.Editor);
winforms-spreadsheet-spell-check-cell-text/VB/SpreadsheetSpellchecking/Form1.vb#L36
If Not e.IsCustom Then
BarManager.SetPopupContextMenu(e.Editor, popupMenu)
spellChecker.Check(e.Editor)
See Also