views:

3447

answers:

5

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

A: 

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

If you need to change the font size of the default Cut/Copy/Paste context menu on text boxes I guess you need to set the ContextMenu property to a custom menu that replaces the default menu.

Hallgrim
+1  A: 

If you are defining your own context menu via a ContextMenuStrip in Windows Forms, use the Font property.

If you are defining your own context menu via a ContextMenu in WPF, use the various Fontxxx properties such as FontFamily and FontSize.

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

OwenP
A: 

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

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

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

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

Of course, it's always better to let the system setting determine the font size. Some people may have changed it to better fit their physical condition (like poor eye sight) or hardware (big/small screen). Whatever you force in your code will be the wrong choice for some people, while you give them no way to change it.

Isak Savo
A: 

In WPF:

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

In WinForms:

contextMenuStrip1.Font = new System.Drawing.Font("Segoe UI", 24F);
Ben Straub
A: 

word wrap in notepad with c#.net