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
  • 546
  • 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
  • 40,767
  • 6
  • 75
  • 112
shf301
  • 30,640
  • 2
  • 50
  • 86
2

Try

FontStyle.Bold | FontStyle.Italic

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

vc 74
  • 35,902
  • 7
  • 66
  • 85
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
  • 23,979
  • 6
  • 45
  • 64
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
  • 24,307
  • 9
  • 78
  • 139
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,365
  • 1
  • 22
  • 44