RichEditControl.PopupMenuShowing Event
Occurs before a context (popup) menu is created for the control’s document every time a context menu is being invoked.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.XtraRichEdit.v19.1.dll
Declaration
Event Data
The PopupMenuShowing event's data class is PopupMenuShowingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Menu | Gets or sets the popup (context) menu for which this event was raised. |
MenuType | Gets a visual element for which the popup menu is invoked. |
Remarks
Handle the PopupMenuShowing event to modify items in the context menu. The current context menu can be accessed via the PopupMenuShowingEventArgs.Menu property.
Example
This example demonstrates how to handle the RichEditControl.PopupMenuShowing
event to customize the RichEditControl‘s context menu. You can remove and disable the existing items, and add new ones using the RichEdit commands.
Note
The CommandPopupMenu
The RichEditMenuType enumeration lists all available context menu types. The following sample modifies the RichEditMenuType.TableCell menu, invoked by right-clicking the table cell.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-customize-the-winforms-richeditcontrol-popup-menu-t541476
private void richEditControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
if ((e.MenuType & RichEditMenuType.TableCell) != 0)
{
// Remove the "Paste" menu item:
e.Menu.RemoveMenuItem(RichEditCommandId.PasteSelection);
// Disable the "Hyperlink..." menu item:
e.Menu.DisableMenuItem(RichEditCommandId.CreateHyperlink);
// Create a RichEdit command, which inserts an inline picture into a document:
IRichEditCommandFactoryService service = (IRichEditCommandFactoryService)richEditControl.GetService(typeof(IRichEditCommandFactoryService));
RichEditCommand cmd = service.CreateCommand(RichEditCommandId.InsertPicture);
//Create a menu item for the new command:
RichEditMenuItemCommandWinAdapter menuItemCommandAdapter = new RichEditMenuItemCommandWinAdapter(cmd);
RichEditMenuItem menuItem = (RichEditMenuItem)menuItemCommandAdapter.CreateMenuItem(DevExpress.Utils.Menu.DXMenuItemPriority.Normal);
menuItem.BeginGroup = true;
e.Menu.Items.Add(menuItem);
// Insert a new item into the Richedit popup menu and handle its click event:
RichEditMenuItem myItem = new RichEditMenuItem("Highlight Selection", new EventHandler(MyClickHandler));
e.Menu.Items.Add(myItem);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PopupMenuShowing event.
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.