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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to prevent the user from modifying the visibility of a particular toolbar in WinForms Menu(MainFrameBarManager)?

Platform: WinForms |
Control: XPToolbar

Modifying the visibility of a particular toolbar

To prevent a particular toolbar from appearing in the toolbar visibility menu, you have to use a custom MainFrameBarManager in your Form like this:


// Will plugin a CustomCommandBarManager
public class CustomMainFrameBarManager : MainFrameBarManager
   public CustomMainFrameBarManager(){}
   public CustomMainFrameBarManager(IContainer container, Form form) : base(container, form)
   {  }
   protected override void CreateCommandBarManager()
      if(this.Form != null)
         this.commandBarManager = new CustomCommandBarManager(this.Form, this);
//Will exclude a particular toolbar from the toolbar visibility menu.
public class CustomCommandBarManager : CommandBarManager
   private ParentBarItem toolbarListItem = null;
   public CustomCommandBarManager(Form form, BarManager manager) : base(form, manager)
   {  }
   // Listen to the Popup event of the ParentBarItem that will contain the toolbar list
   // You will remove unwanted menu items in that event.
   protected override ToolbarListPopupMenu CreateToolbarListPopup()
      ToolbarListPopupMenu popupMenu = base.CreateToolbarListPopup();
      this.toolbarListItem = popupMenu.ParentBarItem;    this.toolbarListItem.Popup += new EventHandler(this.ToolbarList_Popup);  return popupMenu;
   private void ToolbarList_Popup(object sender, EventArgs e)
      ParentBarItem parentItem = sender as ParentBarItem;
      //Remove the BarItem corresponding to the Toolbar that you dont want the user to see
      foreach(BarItem item in parentItem.Items)
         // Looking for the BarName.
         if(item.Text == "Standard") 
            // Note if removing multiple items, use the for loop starting from the bottom of the list.


' Will plugin a CustomCommandBarManager
Public Class CustomMainFrameBarManager Inherits MainFrameBarManager   
    Public Sub New()
    End Sub 'New
    Public Sub New(ByVal container As IContainer, ByVal form As Form) MyBase.New(container, form)
    End Sub 'New
    Protected Overrides Sub CreateCommandBarManager()
       If Not (Me.Form Is Nothing) Then
          Me.commandBarManager = New CustomCommandBarManager(Me.Form, Me)
       End If
    End Sub
End Class
' Will exclude a particular toolbar from the toolbar visibility menu.
Public Class CustomCommandBarManager Inherits CommandBarManager   Private toolbarListItem As ParentBarItem = Nothing
    Public Sub New(ByVal form As Form, ByVal manager As BarManager) MyBase.New(form, manager)
    End Sub 'New
    ' Listen to the Popup event of the ParentBarItem that will contain the toolbar list ' You will remove unwanted menu items in that event.
    Protected Overrides Function CreateToolbarListPopup() As ToolbarListPopupMenu
        Dim popupMenu As ToolbarListPopupMenu = MyBase.CreateToolbarListPopup()
        Me.toolbarListItem = popupMenu.ParentBarItem
        AddHandler Me.toolbarListItem.Popup, AddressOf Me.ToolbarList_Popup
        Return popupMenu
  End Function 'CreateToolbarListPopup
  ' Removing unwanted menu items (corresponding to toolbars) in that event.
  Private Sub ToolbarList_Popup(ByVal sender As Object, ByVal e As EventArgs)
      Dim parentItem As ParentBarItem = CType(sender, ParentBarItem)
      ' Remove the BarItem corresponding to the Toolbar that you don't want the user to see
      Dim item As BarItem
      For Each item In parentItem.Items
          ' Looking for the Bar's BarName.
          If item.Text = "Standard" Then
             Exit For
         End If
  End Sub
End Class

To prevent the user from making it invisible in the Customize dialog, you have to provide a derived "CustomizationPanel". Here are the steps:

1) In your project, select "Add Inherited Control..." in the "Add" menu. In the subsequent dialog, browse to the Syncfusion.Tools.dll assembly (in the ..\Essential Suite\Assemblies folder) and pick the CustomizationPanel class to derive from.

2) Now in your derived control's designer, you can set up a handler for the "toolbarList" CheckedListBox control's ItemCheck event.

3) In this handler, set e.NewValue to be CheckState.Checked for the specific toolbar.

4) Now plug this derived control into the manager as follows:


// In your Form's constructor, after calling InitializeComponent this.mainFramebarManager1.CustomizationDialog.SetCustomizationPanel(new DerivedCustPanel());


2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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