Back to Devexpress

LayoutControl.ShowLayoutTreeViewContextMenu Event

windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-2e32a1b1.md

latest7.4 KB
Original Source

LayoutControl.ShowLayoutTreeViewContextMenu Event

OBSOLETE

You should use the 'LayoutTreeViewPopupMenuShowing' instead

Occurs when the Layout Tree View 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 'LayoutTreeViewPopupMenuShowing' instead", false)]
public event LayoutMenuEventHandler ShowLayoutTreeViewContextMenu
vb
<Browsable(False)>
<EditorBrowsable(EditorBrowsableState.Never)>
<Obsolete("You should use the 'LayoutTreeViewPopupMenuShowing' instead", False)>
Public Event ShowLayoutTreeViewContextMenu As LayoutMenuEventHandler

Event Data

The ShowLayoutTreeViewContextMenu 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

The event fires before the Layout Tree View Context Menu is displayed. It allows you to customize the menu and prevent it from being displayed. To customize the menu use the event’s Menu parameter. You can add new items, which are represented by the DXMenuItem class objects and its descendants, to the menu or remove the existing menu items.

To prevent the menu from being invoked set the Allow parameter to false.

Example

This example handles the LayoutControl.LayoutTreeViewPopupMenuShowing event to add a command to the Layout Tree View Context Menu to toggle the Bold font attribute of the item text.

csharp
using DevExpress.Utils;
using DevExpress.Utils.Menu;
using DevExpress.XtraLayout;
// ...
private void layoutControl1_LayoutTreeViewPopupMenuShowing(object sender, DevExpress.XtraLayout.PopupMenuShowingEventArgs e) {
    BaseLayoutItem layoutItem = e.HitInfo.Item as BaseLayoutItem;
    if (layoutItem == null) return;
    bool isTextBold = layoutItem.AppearanceItemCaption.Font.Bold;
    DXMenuCheckItem menuItem = new DXMenuCheckItem("Bold Text", isTextBold, null, new EventHandler(this.ToggleBoldTextMenuItemClick));
    menuItem.Image = DxImageAssemblyUtil.ImageProvider.GetImage("Bold", ImageSize.Size16x16, ImageType.Colored);
    menuItem.Tag = layoutItem;
    //Add a separator
    e.Menu.Items.Add(new DXMenuItem("-"));
    //Add the "Bold Text" check item.
    e.Menu.Items.Add(menuItem);
}

private void ToggleBoldTextMenuItemClick(object sender, EventArgs e) {
    DXMenuItem menuItem = sender as DXMenuItem;
    BaseLayoutItem layoutItem = menuItem.Tag as BaseLayoutItem;
    if (layoutItem == null) return;
    bool isTextBold = layoutItem.AppearanceItemCaption.Font.Bold;
    Font newFont;
    if (isTextBold)
        newFont = new Font(layoutItem.AppearanceItemCaption.Font, FontStyle.Regular);
    else
        newFont = new Font(layoutItem.AppearanceItemCaption.Font, FontStyle.Bold);
    layoutItem.AppearanceItemCaption.Font = newFont;
}
vb
Imports DevExpress.Utils
Imports DevExpress.Utils.Menu
Imports DevExpress.XtraLayout

Private Sub LayoutControl1_LayoutTreeViewPopupMenuShowing(sender As Object, e As DevExpress.XtraLayout.PopupMenuShowingEventArgs) Handles LayoutControl1.LayoutTreeViewPopupMenuShowing
    Dim layoutItem As BaseLayoutItem = TryCast(e.HitInfo.Item, BaseLayoutItem)
    If layoutItem Is Nothing Then
        Return
    End If
    Dim isTextBold As Boolean = layoutItem.AppearanceItemCaption.Font.Bold
    Dim menuItem As New DXMenuCheckItem("Bold Text", isTextBold, Nothing, New EventHandler(AddressOf Me.ToggleBoldTextMenuItemClick))
    menuItem.Image = DxImageAssemblyUtil.ImageProvider.GetImage("Bold", ImageSize.Size16x16, ImageType.Colored)
    menuItem.Tag = layoutItem
    'Add a separator
    e.Menu.Items.Add(New DXMenuItem("-"))
    'Add the "Bold Text" check item.
    e.Menu.Items.Add(menuItem)
End Sub

Private Sub ToggleBoldTextMenuItemClick(sender As Object, e As EventArgs)
    Dim menuItem As DXMenuItem = TryCast(sender, DXMenuItem)
    Dim layoutItem As BaseLayoutItem = TryCast(menuItem.Tag, BaseLayoutItem)
    If layoutItem Is Nothing Then
        Return
    End If
    Dim isTextBold As Boolean = layoutItem.AppearanceItemCaption.Font.Bold
    Dim newFont As Font
    If isTextBold Then
        newFont = New Font(layoutItem.AppearanceItemCaption.Font, FontStyle.Regular)
    Else
        newFont = New Font(layoutItem.AppearanceItemCaption.Font, FontStyle.Bold)
    End If
    layoutItem.AppearanceItemCaption.Font = newFont
End Sub

See Also

PopupMenuShowing

Context Menu

Customization Form - Layout Control

ShowLayoutTreeView

LayoutControl Class

LayoutControl Members

DevExpress.XtraLayout Namespace