Changing ContextMenu font size in C #

Is it possible to change the font size used in ContextMenu using the .NET Framework 3.5 and C # for a desktop application? This seems to be a system-wide setting, but I would like to change it only in my application.

+4
source share
4 answers

If you define your own context menu through ContextMenuStrip in Windows Forms, use the Font property.

If you define your own context menu using ContextMenu in WPF, use various Fontxxx properties such as FontFamily and FontSize.

You cannot change the default context menus that come with controls; they are determined by the system settings. Therefore, if you want to "Copy / Cut / Paste / etc." a menu with a custom font size for WinForms TextBox , you will need to create a ContextMenuStrip with the appropriate font size and assign it to the TextBox ContextMenuStrip property.

+6
source

You can change the font size of System.Windows.Forms.ContextMenuStrip.

If you need to change the font size in the default Cut / Copy / Paste context menu in the text fields, I think you need to set the ContextMenu property in the user menu, which replaces the default menu.

+1
source

In WPF:

 <Window.ContextMenu FontSize="36"> <!-- ... --> </Window.ContextMenu 

In WinForms:

 contextMenuStrip1.Font = new System.Drawing.Font("Segoe UI", 24F); 
+1
source

You mentioned .NET 3.5 - are you writing in WPF? If so, you can specify the font size for the attached property TextBlock.FontSize

 <Whatever.ContextMenu TextBlock.FontSize="12"> <MenuItem ... /> <!-- Will get the font size from parent --> </Whatever.ContextMenu> 

Or you can specify it in a style that affects all menu items

 <Style TargetType="MenuItem"> <Setter Property="TextBlock.FontSize" Value="12" /> </Style> 

Of course, it is always better that the system setting determines the font size. Some people may have altered it to better match their physical condition (like a bad eye) or their hardware (large / small screen). No matter what you do in your code, for some people it will be the wrong choice, while you will not give them any way to change it.

0
source

Source: https://habr.com/ru/post/1276889/


All Articles