Changing a font style is a bit easier than changing its size, as there is a Font constructor that accepts a font and style as arguments. For example, to bold a label’s font:

Label label = new Label();
. . .
label.Font = new Font( label.Font, FontStyle.Bold );

If you want to keep the original style but also bold it:

label.Font = new Font( label.Font, label.Font.Style | FontStyle.Bold );

The problem with the approach above is that a new Font object is created whether it’s needed or not. Here is a handy method that will bold a font, creating a new Font object only if necessary:

static public Font BoldFont( Font font )
{
    if (font != null)
    {
        FontStyle fontStyle = font.Style;
        if ((fontStyle & FontStyle.Bold) == 0)
        {
            fontStyle |= FontStyle.Bold;
            font = new Font( font, fontStyle );
        }
    }
    return font;
}

For example, to bold a label’s font:

label.Font = BoldFont( label.Font );
Share and Enjoy:
  • Digg
  • Twitter
  • Facebook
  • Reddit
  • StumbleUpon
  • LinkedIn
  • Google Bookmarks
  • Slashdot