在 C# 中更改 ContextMenu 字体大小
是否可以使用 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您通过 Windows 窗体中的 ContextMenuStrip 定义自己的上下文菜单,请使用 Font 属性。
如果您在 WPF 中通过
ContextMenu
定义自己的上下文菜单,请使用各种 Fontxxx 属性,例如 FontFamily 和 FontSize嗯>。您无法更改控件附带的默认上下文菜单; 这些是由系统设置决定的。 因此,如果您想要“复制/剪切/粘贴/等”。 对于 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 aContextMenuStrip
with the appropriate font size and assign it to theTextBox
's ContextMenuStrip property.在 WPF 中:
在 WinForms 中:
In WPF:
In WinForms:
您可以更改 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.
您提到 .NET 3.5 - 您是用 WPF 编写的吗? 如果是这样,您可以为 TextBlock.FontSize 附加属性指定字体大小
,或者,您可以以影响所有菜单项的样式指定它。
当然,最好让系统设置确定字体大小。 有些人可能会更改它以更好地适应他们的身体状况(例如视力不佳)或硬件(大/小屏幕)。 无论你在代码中强加什么,对于某些人来说都是错误的选择,而你却没有给他们提供改变它的方法。
You mention .NET 3.5 - are you writing in WPF? If so, you can specify font size for the TextBlock.FontSize attached property
Or, you could specify it in a style that affects all menu items
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.