在 C# 中更改 ContextMenu 字体大小

发布于 2024-07-06 07:48:03 字数 99 浏览 5 评论 0原文

是否可以使用 .NET Framework 3.5 和 C# 更改桌面应用程序的 ContextMenu 中使用的字体大小? 这似乎是系统范围的设置,但我只想在我的应用程序中更改它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妄断弥空 2024-07-13 07:48:03

如果您通过 Windows 窗体中的 ContextMenuStrip 定义自己的上下文菜单,请使用 Font 属性。

如果您在 WPF 中通过 ContextMenu 定义自己的上下文菜单,请使用各种 Fontxxx 属性,例如 FontFamilyFontSize嗯>。

您无法更改控件附带的默认上下文菜单; 这些是由系统设置决定的。 因此,如果您想要“复制/剪切/粘贴/等”。 对于 WinForms TextBox 具有自定义字体大小的菜单,您必须创建一个具有适当字体大小的 ContextMenuStrip 并将其分配给 TextBox > 的 ContextMenuStrip 属性。

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.

酒几许 2024-07-13 07:48:03

在 WPF 中:

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

在 WinForms 中:

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

In WPF:

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

In WinForms:

contextMenuStrip1.Font = new System.Drawing.Font("Segoe UI", 24F);
救赎№ 2024-07-13 07:48:03

您可以更改 System.Windows.Forms.ContextMenuStrip 的字体大小。

如果您需要更改文本框上默认剪切/复制/粘贴上下文菜单的字体大小,我想您需要将 ContextMenu 属性设置为替换默认菜单的自定义菜单。

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.

迷途知返 2024-07-13 07:48:03

您提到 .NET 3.5 - 您是用 WPF 编写的吗? 如果是这样,您可以为 TextBlock.FontSize 附加属性指定字体大小

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

,或者,您可以以影响所有菜单项的样式指定它。

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

当然,最好让系统设置确定字体大小。 有些人可能会更改它以更好地适应他们的身体状况(例如视力不佳)或硬件(大/小屏幕)。 无论你在代码中强加什么,对于某些人来说都是错误的选择,而你却没有给他们提供改变它的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文