首页 文章

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

提问于
浏览
1

可能重复:c#使字体为斜体和粗体

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

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

5 回答

  • 1

    FontStyleFlags 枚举:

    [FlagsAttribute]
    public enum FontStyle
    

    用它就像

    x.FontStyle = FontStyle.Bold | FontStyle.Italic;
    

    要么

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

    尝试

    FontStyle.Bold | FontStyle.Italic
    

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

  • 8

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

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

    FontStyleFlags 枚举 . 你通过或者将它们一起发送为粗体和斜体: FontStyle.Bold | FontStyle.Italic

  • 0

    它是一个位掩码枚举 . 要组合成员,请使用按位运算符(|),如下所示:

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

    另见Using a bitmask in C#

相关问题