I have a little problem. I have one 1 RichTextBox and 2 Buttons.
I have that 2 buttons for \"toggle Bold FStyle\" and \"toggle Italic FStyle\".
I want to tog
The easiest way is to use bitwise XOR (^
), which just toggles the value:
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font,
richTextBox1.SelectionFont.Style ^ FontStyle.Bold);
}
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.SelectionFont = new Font(richTextBox1.Font,
richTextBox1.SelectionFont.Style ^ FontStyle.Italic);
}