Category / Section
How to hide an item from customization in WinForms MainFrameBarManager (Menu)?
2 mins read
Hide an item from customization
To prevent the item from being customized via Alt+Click the item should be prevented appearing from the customization dialog. Please refer the below code snippet which illustrates this:
C#
this.mainFrameBarManager1.CustomizingItemChanged += new EventHandler(mainFrameBarManager1_CustomizingItemChanged); this.mainFrameBarManager1.CustomizationBegin += new EventHandler(mainFrameBarManager1_CustomizationBegin); this.mainFrameBarManager1.CustomizationDone += new EventHandler(mainFrameBarManager1_CustomizationDone); void mainFrameBarManager1_CustomizationDone(object sender, EventArgs e) { //throw new Exception("The method or operation is not implemented."); // Unhide the item. this.parentBarItem1.Visible = true; // Make the category visible again in the customization dialog. this.mainFrameBarManager1.CategoriesToIgnoreInCustDialog.Remove(this.parentBarItem1.CategoryIndex); } void mainFrameBarManager1_CustomizationBegin(object sender, EventArgs e) { //throw new Exception("The method or operation is not implemented."); // Hide an item’s Category from appearing in the Customization Dialog. this.mainFrameBarManager1.CategoriesToIgnoreInCustDialog.Add(this.parentBarItem1.CategoryIndex); // Also hide the item itself. this.parentBarItem1.Visible = false; } void mainFrameBarManager1_CustomizingItemChanged(object sender, EventArgs e) { //throw new Exception("The method or operation is not implemented."); // Prevent a particular item from being Customized via Alt + Click. if (this.mainFrameBarManager1.CustomizingItem == this.parentBarItem1) { this.mainFrameBarManager1.EndDragAndDropCustomizing(); } }
VB
AddHandler MainFrameBarManager1.CustomizationBegin, AddressOf Customization_Begin AddHandler MainFrameBarManager1.CustomizationDone, AddressOf Customization_Done AddHandler MainFrameBarManager1.CustomizingItemChanged, AddressOf mainFrameBarManager1_CustomizingItemChanged Private Sub mainFrameBarManager1_CustomizingItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainFrameBarManager1.CustomizingItemChanged ' Prevent a particular item from being Customized via Alt + Click. If Me.MainFrameBarManager1.CustomizingItem Is Me.ParentBarItem1 Then Me.MainFrameBarManager1.EndDragAndDropCustomizing() End If End Sub 'mainFrameBarManager1_CustomizingItemChanged Private Sub Customization_Begin(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainFrameBarManager1.CustomizationBegin ' Hide an item’s Category from appearing in the Customization Dialog. Me.MainFrameBarManager1.CategoriesToIgnoreInCustDialog.Add(Me.ParentBarItem1.CategoryIndex) ' Also hide the item itself. Me.ParentBarItem1.Visible = False End Sub 'Customization_Begin Private Sub Customization_Done(ByVal sender As Object, ByVal e As System.EventArgs) Handles MainFrameBarManager1.CustomizationDone ' Unhide the item. Me.ParentBarItem1.Visible = True ' Make the category visible again in the customization dialog. Me.MainFrameBarManager1.CategoriesToIgnoreInCustDialog.Remove(Me.ParentBarItem1.CategoryIndex) End Sub 'Customization_Done