Implement ContextMenuStripEx enhanced context menus in Windows Forms applications. Use this when working with context menus, right-click functionality, or popup menus with custom items. Covers menu configuration, multi-level menus, keyboard shortcuts, and appearance customization in WinForms.
Guide for implementing enhanced context menus with rich item types, multi-level navigation, and extensive customization options in Windows Forms applications.
Use this skill when you need to:
ContextMenuStripEx is an enhanced version of the standard Windows Forms ContextMenuStrip that provides:
Key Features:
📄 Read: references/getting-started.md
📄 Read: references/menu-item-states.md
📄 Read: references/multilevel-menus.md
📄 Read: references/menu-behavior.md
📄 Read: references/keyboard-and-touch.md
Via Designer:
1. Drag ContextMenuStripEx from toolbox to form
(appears in component tray)
2. Click "Type Here" to add menu items
3. Select item type (MenuItem, TextBox, ComboBox, Separator)
4. Configure item properties in Properties panel
5. Right-click target control → Properties → ContextMenuStrip
6. Select the ContextMenuStripEx instance
Via Code:
using Syncfusion.Windows.Forms.Tools;
using System.Windows.Forms;
// Declarations
private ContextMenuStripEx contextMenuStripEx;
private ToolStripMenuItem menuItemCut;
private ToolStripMenuItem menuItemCopy;
private ToolStripMenuItem menuItemPaste;
private RichTextBox richTextBox1;
// Initialization
private void InitializeContextMenu()
{
// Create context menu
this.contextMenuStripEx = new ContextMenuStripEx();
// Create menu items
this.menuItemCut = new ToolStripMenuItem();
this.menuItemCopy = new ToolStripMenuItem();
this.menuItemPaste = new ToolStripMenuItem();
// Configure menu items
this.menuItemCut.Text = "Cut";
this.menuItemCut.ShortcutKeys = Keys.Control | Keys.X;
this.menuItemCut.Click += MenuItemCut_Click;
this.menuItemCopy.Text = "Copy";
this.menuItemCopy.ShortcutKeys = Keys.Control | Keys.C;
this.menuItemCopy.Click += MenuItemCopy_Click;
this.menuItemPaste.Text = "Paste";
this.menuItemPaste.ShortcutKeys = Keys.Control | Keys.V;
this.menuItemPaste.Click += MenuItemPaste_Click;
// Add items to context menu
this.contextMenuStripEx.Items.AddRange(new ToolStripItem[] {
this.menuItemCut,
this.menuItemCopy,
this.menuItemPaste
});
// Associate with control
this.richTextBox1 = new RichTextBox();
this.richTextBox1.ContextMenuStrip = this.contextMenuStripEx;
this.Controls.Add(this.richTextBox1);
}
// Event handlers
private void MenuItemCut_Click(object sender, EventArgs e)
{
richTextBox1.Cut();
}
private void MenuItemCopy_Click(object sender, EventArgs e)
{
richTextBox1.Copy();
}
private void MenuItemPaste_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
}
private void CreateEditContextMenu()
{
var contextMenu = new ContextMenuStripEx();
var cutItem = new ToolStripMenuItem("Cut", null, (s, e) => textBox.Cut());
cutItem.ShortcutKeys = Keys.Control | Keys.X;
var copyItem = new ToolStripMenuItem("Copy", null, (s, e) => textBox.Copy());
copyItem.ShortcutKeys = Keys.Control | Keys.C;
var pasteItem = new ToolStripMenuItem("Paste", null, (s, e) => textBox.Paste());
pasteItem.ShortcutKeys = Keys.Control | Keys.V;
contextMenu.Items.AddRange(new ToolStripItem[] {
cutItem, copyItem, pasteItem
});
textBox.ContextMenuStrip = contextMenu;
}
private void CreateMultiLevelMenu()
{
var contextMenu = new ContextMenuStripEx();
// Parent menu item with submenus
var newMenuItem = new ToolStripMenuItem("New");
// Submenu items
var newDocItem = new ToolStripMenuItem("New Document");
var newProjectItem = new ToolStripMenuItem("New Project");
var newFileItem = new ToolStripMenuItem("New File");
// Add submenus to parent
newMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
newDocItem, newProjectItem, newFileItem
});
// Add to context menu
contextMenu.Items.Add(newMenuItem);
control.ContextMenuStrip = contextMenu;
}
private void CreateDynamicCheckedMenu()
{
var contextMenu = new ContextMenuStripEx();
var boldItem = new ToolStripMenuItem("Bold");
boldItem.CheckOnClick = true;
boldItem.Checked = false;
boldItem.Click += (s, e) => {
var item = s as ToolStripMenuItem;
// Apply bold formatting based on checked state
ApplyBoldFormatting(item.Checked);
};
var italicItem = new ToolStripMenuItem("Italic");
italicItem.CheckOnClick = true;
italicItem.Checked = false;
var underlineItem = new ToolStripMenuItem("Underline");
underlineItem.CheckOnClick = true;
underlineItem.Checked = false;
contextMenu.Items.AddRange(new ToolStripItem[] {
boldItem, italicItem, underlineItem
});
richTextBox.ContextMenuStrip = contextMenu;
}
private void CreateMixedItemMenu()
{
var contextMenu = new ContextMenuStripEx();
// Menu item
var searchItem = new ToolStripMenuItem("Search");
// TextBox for input
var searchBox = new ToolStripTextBox();
searchBox.Text = "Enter search term...";
// Separator
var separator = new ToolStripSeparator();
// ComboBox for options
var filterCombo = new ToolStripComboBox();
filterCombo.Items.AddRange(new object[] { "All", "Documents", "Images" });
filterCombo.SelectedIndex = 0;
// Add all items
contextMenu.Items.AddRange(new ToolStripItem[] {
searchItem, searchBox, separator, filterCombo
});
control.ContextMenuStrip = contextMenu;
}
private void UpdateMenuItemStates()
{
// Enable/disable based on application state
menuItemCut.Enabled = textBox.SelectionLength > 0;
menuItemCopy.Enabled = textBox.SelectionLength > 0;
menuItemPaste.Enabled = Clipboard.ContainsText();
}
private void ContextMenu_Opening(object sender, CancelEventArgs e)
{
// Update states before menu opens
UpdateMenuItemStates();
}
// Subscribe to Opening event
contextMenuStripEx.Opening += ContextMenu_Opening;
Items: Collection of ToolStripItems in the menuAutoClose: Whether menu closes on user actionsBackColor: Background color of the menuFont: Font applied to all menu itemsSize: Height and width of the menuRenderMode: Painting style (Professional, System, Custom)Text: Display text for the menu itemChecked: Whether check mark appearsCheckedState: State (Checked, Unchecked, Indeterminate)Enabled: Whether item is enabledShortcutKeys: Keyboard shortcutShowShortcutKeys: Display shortcut in menuDropDownItems: Submenu items collectionToolTipText: Tooltip when hoveringClick: Fires when menu item is clickedCheckedChanged: Fires when checked state changesOpening: Fires before context menu opensClosed: Fires when context menu closesImplement standard editing operations (cut, copy, paste, select all) with keyboard shortcuts displayed.
Reference: getting-started.md, keyboard-and-touch.md
Create a menu with checkable items for toggling features (show toolbar, show status bar, word wrap).
Reference: menu-item-states.md, menu-behavior.md
Build a hierarchical menu for file operations (New → Document/Project/File, Open, Save, Close).
Reference: multilevel-menus.md, toolstrip-item-types.md
Combine TextBox for input and ComboBox for filter selection within the context menu.
Reference: toolstrip-item-types.md, appearance-customization.md
Enable/disable menu items based on current selection or application state.
Reference: menu-item-states.md, menu-behavior.md
Menu Not Appearing:
Shortcuts Not Working:
Items Not Enabled:
Submenus Not Showing:
For detailed information on specific features, navigate to the appropriate reference file listed in the Documentation and Navigation Guide section.