windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-e2c2da27.md
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
[DXCategory("Events")]
public event PopupMenuShowingEventHandler LayoutTreeViewPopupMenuShowing
<DXCategory("Events")>
Public Event LayoutTreeViewPopupMenuShowing As PopupMenuShowingEventHandler
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. |
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.
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.
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;
}
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