-1

Here is my code for styling selected text in richtextbox to italic. However, if the selected text is italic, how can I remove that styling?

    private void btnitalic_Click(object sender, EventArgs e)
    {
        var italictext = this.ActiveControl as RichTextBox;
        if (italictext != null)
        {
            italictext.SelectionFont = new Font(italictext.Font, FontStyle.Italic);
        }

    }
e_i_pi
  • 4,590
  • 4
  • 27
  • 45

1 Answers1

-1

The easy way you first formal all selected text before convert it to italic:

if (italictext != null)
        {
            italictext.SelectionFont = new Font(italictext.Font, FontStyle.Regular);
            italictext.SelectionFont = new Font(italictext.Font, FontStyle.Italic);
        }
Rai Vu
  • 1,595
  • 1
  • 20
  • 30