本文介绍了从控件的字体中删除FontStyle Bold的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这真是个菜鸟,但是我似乎找不到任何东西...

I feel like a real noob posting this, but I can't seem to find anything for this...

我有一个控件,我基本上是试图在粗体和非粗体之间切换字体.这应该很简单...

I have a control that I'm basically trying to toggle the fontstyle between bold and not bold. This should be simple...

但是,您无法访问Control.Font.Bold属性,因为它是只读的,因此,您需要更改Font属性.

However, you can't acccess the Control.Font.Bold property as it is read only, therefore, you need to change the Font property.

要使其变粗,我只需这样做:

To make it bold, I just do this:

this.btn_buttonBolding.Font = new Font(this.btn_buttonBolding.Font, FontStyle.Bold);

不理想,但是可以.但是,如何删除这种粗体(一旦已经粗体了)?

Not ideal, but it works. However, how do I go about removing this bold style (once it is bold already)?

我努力寻找重复的东西;我能找到的最接近的是这个,但并不能完全回答我的情况:从FontStyle中减去标志(切换FontStyles)[C#]

I looked hard for duplicates; closest I could find was this, but it doesn't quite answer my situation:Substract Flag From FontStyle (Toggling FontStyles) [C#]

这给出了如何设置而不是删除它的方法:以编程方式更改字体

And this which gives how to set it, but not remove it: Change a font programmatically

我想念一个简单的字体构造函数来做到这一点吗?还是我只是缺少一些轻松的东西?

Am I missing a simple constructor for the font that could do this? Or am I just missing something easier?

推荐答案

FontStyle枚举包含5个不同的值.重置您之前设置的是 FontStyle.Regular

The FontStyle enum contains 5 distinct values.The one that reset your previous set is FontStyle.Regular

常规普通文本.
粗体.粗体.
斜体斜体文本.
下划线带下划线的文本.
删除线,中间有一行.

Regular Normal text.
Bold Bold text.
Italic Italic text.
Underline Underlined text.
Strikeout Text with a line through the middle.

这是按位枚举,其中Regular为0.因此,单独设置此值会重置所有其他标志

It's a bitwise enum where Regular is 0. So setting this value alone reset all other flags

这篇关于从控件的字体中删除FontStyle Bold的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 22:53