Back to Devexpress

LayoutControl.ShowContextMenu Event

windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-dc073b9b.md

latest5.2 KB
Original Source

LayoutControl.ShowContextMenu Event

OBSOLETE

You should use the 'PopupMenuShowing' instead

Occurs when the Context Menu is about to be displayed.

Namespace : DevExpress.XtraLayout

Assembly : DevExpress.XtraLayout.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("You should use the 'PopupMenuShowing' instead", false)]
public event LayoutMenuEventHandler ShowContextMenu
vb
<Browsable(False)>
<EditorBrowsable(EditorBrowsableState.Never)>
<Obsolete("You should use the 'PopupMenuShowing' instead", False)>
Public Event ShowContextMenu As LayoutMenuEventHandler

Event Data

The ShowContextMenu event's data class is LayoutMenuEventArgs. The following properties provide information specific to this event:

PropertyDescription
AllowGets or sets whether the menu is allowed to be displayed. Inherited from PopupMenuShowingEventArgs.
HitInfoContains information on the clicked point within the Layout Control. Inherited from PopupMenuShowingEventArgs.
MenuGets or sets the menu that is about to be displayed. Inherited from PopupMenuShowingEventArgs.
PointGets the point at which the menu is about to be displayed. Inherited from PopupMenuShowingEventArgs.

Remarks

Use the LayoutControl.PopupMenuShowing event instead.

Example

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:

csharp
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();
}
vb
Imports DevExpress.XtraLayout
Imports DevExpress.Utils.Menu

Private Sub LayoutControl1_PopupMenuShowing(ByVal sender As System.Object, _
  ByVal e As PopupMenuShowingEventArgs) Handles LayoutControl1.PopupMenuShowing
    e.Menu.Items.Add(New DXMenuItem("&Save Layout", AddressOf SaveLayout))
    e.Menu.Items.Add(New DXMenuItem("&Restore Layout", AddressOf RestoreLayout))
End Sub

Private Sub SaveLayout(ByVal sender As Object, ByVal e As EventArgs)
    LayoutControl1.SetDefaultLayout()
End Sub

Private Sub RestoreLayout(ByVal sender As Object, ByVal e As EventArgs)
    LayoutControl1.RestoreDefaultLayout()
End Sub

See Also

LayoutTreeViewPopupMenuShowing

Context Menu

LayoutControl Class

LayoutControl Members

DevExpress.XtraLayout Namespace