可能重复:c#使字体为斜体和粗体
如何将字体的字体样式设置为粗斜体?
我无法将字体的fontstyle设置为粗体斜体..我在哪里以及如何设置>?
FontStyle 是 Flags 枚举:
FontStyle
Flags
[FlagsAttribute] public enum FontStyle
用它就像
x.FontStyle = FontStyle.Bold | FontStyle.Italic;
要么
Button1.Font = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Bold | FontStyle.Italic);
尝试
FontStyle.Bold | FontStyle.Italic
(FontStyle用FlagsAttribute修饰,允许以这种方式组合选项)
FontStyle枚举使用FlagsAttribute因此您可以使用按位运算符将多个FontStyles作为单个参数传递 .
if (Button1.Font.Style != FontStyle.Bold || Button1.Font.Style != FontStyle.Italic) Button1.Font = new Font(Button1.Font, FontStyle.Bold | FontStyle.Italic);
FontStyle 是 Flags 枚举 . 你通过或者将它们一起发送为粗体和斜体: FontStyle.Bold | FontStyle.Italic
它是一个位掩码枚举 . 要组合成员,请使用按位运算符(|),如下所示:
label1.Font = new Font(label1.Font, FontStyle.Bold | FontStyle.Italic);
另见Using a bitmask in C#
5 回答
FontStyle
是Flags
枚举:用它就像
要么
尝试
(FontStyle用FlagsAttribute修饰,允许以这种方式组合选项)
FontStyle枚举使用FlagsAttribute因此您可以使用按位运算符将多个FontStyles作为单个参数传递 .
FontStyle
是Flags
枚举 . 你通过或者将它们一起发送为粗体和斜体:FontStyle.Bold | FontStyle.Italic
它是一个位掩码枚举 . 要组合成员,请使用按位运算符(|),如下所示:
另见Using a bitmask in C#