1

Possible Duplicate:
c# Make font italic and bold

How do i set the font style of a font to bold italic?

I am unable to set the fontstyle of font to bold italic.. where and how can i set it >?

Community
  • 1
  • 1
Nick
  • 586
  • 2
  • 7
  • 22

5 Answers5

8

FontStyle is a Flags enumeration. You send bold and italic by or'ing them together: FontStyle.Bold | FontStyle.Italic

phoog
  • 42,068
  • 6
  • 79
  • 117
shf301
  • 31,086
  • 2
  • 52
  • 86
2

Try

FontStyle.Bold | FontStyle.Italic

(FontStyle is decorated with FlagsAttribute which allows combining options this way)

vc 74
  • 37,131
  • 7
  • 73
  • 89
1

The FontStyle is a Flags enum:

[FlagsAttribute]
public enum FontStyle

use it like

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

OR

Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold | FontStyle.Italic);
Mithrandir
  • 24,869
  • 6
  • 50
  • 66
0

It is a bitmask enumeration. To combine members use the bit-wise OR operator (|) like this:

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

See also Using a bitmask in C#

Community
  • 1
  • 1
BlueMonkMN
  • 25,079
  • 9
  • 80
  • 146
0

The FontStyle Enumeration uses the FlagsAttribute thus you can use bitwise operators to pass multiple FontStyles as a single parameter.

if (Button1.Font.Style != FontStyle.Bold || Button1.Font.Style != FontStyle.Italic)
            Button1.Font = new Font(Button1.Font, FontStyle.Bold | FontStyle.Italic);
MyItchyChin
  • 13,733
  • 1
  • 24
  • 44