Articles in this section
Category / Section

How to prevent a particular toolbar from appearing in toolbar visibility menu?

3 mins read

Modifying the visibility of a particular toolbar

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

C#

// 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") 
         { 
            parentItem.Items.Remove(item); 
            // Note if removing multiple items, use the for loop starting from the bottom of the list.
             break;
         }
      }
   }
}

VB

' 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
             parentItem.Items.Remove(item)
             Exit For
         End If
      Next
  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:

C#

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

 

Conclusion

I hope you enjoyed learning about how to prevent a particular toolbar from appearing in toolbar visibility menu.

You can refer to our WinForms XPToolbar feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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