Changing font in C#

WebTechRiser.com > C# > Changing font in C#

FontStyle is an enumeration you can Or them together to add or Xor to remove.

i.e.

to add underlining to existing style:

textBox1.Font = new Font(
    textBox1.Font, textBox1.Font.Style | FontStyle.Underline
);

to remove underlining from style:

textBox1.Font = new Font(
    textBox1.Font, textBox1.Font.Style ^ FontStyle.Underline
);

and you can check for which Enumerations are in the Font.Style by doing this.

if ((textBox1.Font.Style.HasFlag(FontStyle.Underline)))
{
   textBox1.Font = new Font(
      textBox1.Font, textBox1.Font.Style ^ FontStyle.Underline
   );
} else {
   textBox1.Font = new Font(
      textBox1.Font, textBox1.Font.Style | FontStyle.Underline
   );
}
Also read:  IP Address (IP4) Validator in C#
Category C#

Leave Your Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.