【问题标题】:Why is the fontstyle enumeration in C# missing bold italic? [duplicate]为什么 C# 中的 fontstyle 枚举缺少粗斜体? [复制]
【发布时间】:2012-01-27 04:03:05
【问题描述】:

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

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

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

【问题讨论】:

  • System.Drawing.Font? WPF 字体?
  • 问重复的问题...仍然得到 5 个正确答案...不接受任何一个。

标签: c# fonts font-face


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    试试

    FontStyle.Bold | FontStyle.Italic
    

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

    【讨论】:

      【解决方案3】:

      FontStyle 是一个 Flags 枚举:

      [FlagsAttribute]
      public enum FontStyle
      

      像这样使用它

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

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

      【讨论】:

        【解决方案4】:

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

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

        另见Using a bitmask in C#

        【讨论】:

          【解决方案5】:

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

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2012-07-08
            • 1970-01-01
            • 1970-01-01
            • 2011-07-06
            相关资源
            最近更新 更多