Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Implement custom functionality for layout context menu

The following example shows how to add custom menu items to the Context Menu via the LayoutControl.PopupMenuShowing event.

Two menu items are added: Save Layout which saves the current layout to a memory buffer; and Restore Layout which restores the previously saved layout. Clicking these items will call the LayoutControl.SetDefaultLayout and LayoutControl.RestoreDefaultLayout methods respectively.

The image below shows the resultant menu:

Ex_ShowContextMenu

using DevExpress.XtraLayout;
using DevExpress.Utils.Menu;

private void layoutControl1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
   e.Menu.Items.Add(new DXMenuItem("&Save Layout", new EventHandler(SaveLayout)));
   e.Menu.Items.Add(new DXMenuItem("&Restore Layout", new EventHandler(RestoreLayout)));
}

private void SaveLayout(object sender, EventArgs e) {
   layoutControl1.SetDefaultLayout();
}

private void RestoreLayout(object sender, EventArgs e) {
   layoutControl1.RestoreDefaultLayout();
}