I have a label with text in Bold and Italic . I want to change those font properties through a button click.
I got to know of the code Label1.Font = new Font(Label1.Font, FontStyle.Regular);
But from this code it will undo both BOLD & ITALIC properties. I want only to remove bold property.....
Are there anything like fontsyle.bold = false
?
Use Font.Style of original font when creating new one, use & ~
to flip styles
label1.Font = new Font(label1.Font, label1.Font.Style & ~FontStyle.Bold);
You can try this also --
label1.Font = new Font("Arial", 24,FontStyle.Bold);
or
mainForm.lblName.Font = new Font("Arial", mainForm.lblName.Font.Size);
The constructor takes different parameters. see more
The best option is to use bitcodes and the XOR operator ^
try this code:
Label1.Font = new Font(Label1.Font.Style ^ FontStyle.Regular);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With