FontDialog (bold, italic)

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.
 
T

Tom Dacon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top