FontDialog (bold, italic)

  • Thread starter Thread starter Tim Bücker
  • Start date Start date
T

Tim Bücker

Hello.

I want to use the FontDialog to select a font, a font color and a font style
(bold, italic, ...).
Having a property for the font and font color, these are easy to read out
once the user clicked Ok.
But how can I determine if the user selected bold, italic or normal font
style as there is no property FontStyle or something like that!

Very strange is that I didn´t find anything searching the net or the msdn...
Thanks a lot for any hint! Greetings,
Tim.
 
The dialog's Font property returns a Font object that encapsulates the
font's name, its size, and its style. The Font's Style property contains the
style bits, from the FontStyle enumeration. The members of the FontStyle
enumeration define bold, italic, underline, and so forth. So you can inspect
the Font's Style property with code such as:

Font f = dlg.Font;
bool isBold = ( (f.Style & FontStyle.Bold) != 0 );

The code's off the top of my head, so I can't guarantee that it will
compile, but it should give you the idea.

Tom Dacon
Dacon Software Consulting
 
Back
Top