Category / Section
How to change the CustomTextFont property of the WinForms Popup menu items which gets shown when right click on toolbar area?
1 min read
CustomTextFont
The text font in the context menu can be changed by getting the CommandBar using GetCommandBarManager method and get hold of DockBarContextMenu. Now the ParentBarItem's BeforePopup event has to handled to change the text font of Popup menu items. Please refer the below code snippet which illustrates this:
C#
this.mainFrameBarManager1.GetCommandBarManager().DockBarContextMenu.ParentBarItem.BeforePopup+=new CancelEventHandler(ParentBarItem_BeforePopup); private void ParentBarItem_BeforePopup(object sender, CancelEventArgs e) { foreach(BarItem baritem in this.mainFrameBarManager1.GetCommandBarManager().DockBarContextMenu.ParentBarItem.Items) { baritem.CustomTextFont=new Font("Times New Roman",8.25F); } }
VB
AddHandler mainFrameBarManager1.GetCommandBarManager().DockBarContextMenu.ParentBarItem.BeforePopup, AddressOf ParentBarItem_BeforePopup Private Sub ParentBarItem_BeforePopup(ByVal sender As Object, ByVal e As CancelEventArgs) For Each baritem As BarItem In Me.mainFrameBarManager1.GetCommandBarManager().DockBarContextMenu.ParentBarItem.Items baritem.CustomTextFont = New Font("Times New Roman",8.25F) Next baritem End Sub