Skip to main content

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.v24.2.dll

Declaration

[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("You should use the 'LayoutTreeViewPopupMenuShowing' instead", false)]
public event LayoutMenuEventHandler ShowLayoutTreeViewContextMenu

Event Data

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

Property Description
Allow Gets or sets whether the menu is allowed to be displayed. Inherited from PopupMenuShowingEventArgs.
HitInfo Contains information on the clicked point within the Layout Control. Inherited from PopupMenuShowingEventArgs.
Menu Gets or sets the menu that is about to be displayed. Inherited from PopupMenuShowingEventArgs.
Point Gets 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.

tbhTreeViewMenu

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;
}
See Also