Bob Gatto

Bob Gatto

  • NA
  • 44
  • 8.2k

how do I change font style of selected text ONLY in a rich text box?

Dec 18 2020 6:54 AM
I have a rich text box on my form and all I want the user to select an area of text, click on a 'B' icon and set only the selected text to bold. And after that when they continue to type the bold setting should be turned off and the previous font setting should be used.
 
The code I'm using is this:
  1. Font fnt = new Font(richTextBox1.Font, FontStyle.Bold);
  2. richTextBox1.SelectionFont = fnt; 
 And this does set the selected text to bold. However, when I continue typing, bold is still set.
 
So how do I turn off the bold and leave the font settings as they were before the selection?
 
Thanks for the help.

Answers (2)