Skip to main content
A newer version of this page is available. .

LayoutControl.LayoutTreeViewPopupMenuShowing Event

Occurs when the Layout Tree View Context Menu is about to be displayed.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v19.1.dll

Declaration

[DXCategory("Events")]
public event PopupMenuShowingEventHandler LayoutTreeViewPopupMenuShowing

Event Data

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

Property Description
Allow Gets or sets whether the menu is allowed to be displayed.
HitInfo Contains information on the clicked point within the Layout Control.
Menu Gets or sets the menu that is about to be displayed.
Point Gets the point at which the menu is about to be displayed.

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, 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