)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: DockingManager |
Published Date: April 30, 2018 |
Last Revised Date: May 23, 2019

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

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon