Articles in this section
Category / Section

How to remove the menu item from docked window context menu in DockingManager?

4 mins read

Context menu items in dock window caption can be customized using DockContextMenu event of DockingManager. The DockContextMenuEventArgs allows to add/remove the menu items using its ContextMenu option.  So, we can add/remove the ContextMenuItem by passing the corresponding BarItem to add/remove function.

 

Here we have added the new menu item "File" and removed the default menu items “Hide” and “Dock to”.  Please make use of the below ContextMenuItemText for remove the default menu items from context menu. 

 

ContextMenuItem

Corresponding BarItem Text

Floating

Dockable

MDI Child

Auto-Hide

Hide

Dock to

&Floating

Doc&kable

&MDI Child

&Auto-Hide

&Hide

Dock to

 

The following code demonstrates the same.

C#

//Add/Remove ContextMenu
this.dockingManager1.DockContextMenu += DockingManager1_DockContextMenu;
 
private void DockingManager1_DockContextMenu(object sender, DockContextMenuEventArgs arg)
{
///
///Add ContextMenuItem
///
//Initialize and set the properties.
this.fileItem = new Syncfusion.Windows.Forms.Tools.XPMenus.ParentBarItem();
this.bar1 = new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem();
this.fileItem.Text = "File";
this.bar1.Text = "Exit";
this.fileItem.Items.AddRange(new Syncfusion.Windows.Forms.Tools.XPMenus.BarItem[] { this.bar1 });
arg.ContextMenu.ParentBarItem.Items.Add(fileItem);
 
//Remove ContextMenuItem
BarItem item = arg.ContextMenu.ParentBarItem.Items[4] as BarItem;
BarItem item1 = arg.ContextMenu.ParentBarItem.Items[5] as BarItem;
if (item != null && item.Text == "&Hide")
{
arg.ContextMenu.ParentBarItem.Items.Remove(item);
}
if (item1 != null && item1.Text == "Dock to")
{
arg.ContextMenu.ParentBarItem.Items.Remove(item1);
}
}
 

 

'Add/Remove ContextMenu
AddHandler Me.dockingManager1.DockContextMenu, AddressOf DockingManager1_DockContextMenu
 
'''
'''Add ContextMenuItem
'''
'Initialize and set the properties.
Me.fileItem = New Syncfusion.Windows.Forms.Tools.XPMenus.ParentBarItem()
Me.bar1 = New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem()
Me.fileItem.Text = "File"
Me.bar1.Text = "Exit"
Me.fileItem.Items.AddRange(New Syncfusion.Windows.Forms.Tools.XPMenus.BarItem() { Me.bar1 })
arg.ContextMenu.ParentBarItem.Items.Add(fileItem)
 
'Remove ContextMenuItem
Dim item As BarItem = TryCast(arg.ContextMenu.ParentBarItem.Items(4), BarItem)
Dim item1 As BarItem = TryCast(arg.ContextMenu.ParentBarItem.Items(5), BarItem)
If item IsNot Nothing AndAlso item.Text = "&Hide" Then
arg.ContextMenu.ParentBarItem.Items.Remove(item)
End If
If item1 IsNot Nothing AndAlso item1.Text = "Dock to" Then
arg.ContextMenu.ParentBarItem.Items.Remove(item1)
End If

 

Screenshot

 

Default contextmenu

Figure 1: Default ContextMenu

 

Showing add or remove contextmenuitem

Figure 2: After add/remove ContextMenuItem.

 

Sample:

 

C#:  DockingManagerExample

 

VB:  DockingManagerExample

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied