为什么C#中的fontstyle枚举缺少粗体斜体?

时间:2012-01-26 19:52:40

标签: c# fonts font-face

  

可能重复:
  c# Make font italic and bold

如何将字体的字体样式设置为粗体斜体?

我无法将字体的fontstyle设置为粗斜体..我在哪里以及如何设置>?

5 个答案:

答案 0 :(得分:8)

FontStyle是一个Flags枚举。您通过或将它们组合在一起发送粗体和斜体:FontStyle.Bold | FontStyle.Italic

答案 1 :(得分:2)

尝试

FontStyle.Bold | FontStyle.Italic

(FontStyle用FlagsAttribute修饰,允许以这种方式组合选项)

答案 2 :(得分:1)

FontStyleFlags枚举:

[FlagsAttribute]
public enum FontStyle

一样使用它
x.FontStyle = FontStyle.Bold | FontStyle.Italic;

OR

Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold | FontStyle.Italic);

答案 3 :(得分:0)

这是一个位掩码枚举。要组合成员,请使用像这样的按位运算符(|):

label1.Font = new Font(label1.Font, FontStyle.Bold | FontStyle.Italic);

另见Using a bitmask in C#

答案 4 :(得分:0)

FontStyle Enumeration使用FlagsAttribute,因此您可以使用按位运算符将多个FontStyles作为单个参数传递。

if (Button1.Font.Style != FontStyle.Bold || Button1.Font.Style != FontStyle.Italic)
            Button1.Font = new Font(Button1.Font, FontStyle.Bold | FontStyle.Italic);