I want to create a text editor where I can make text bold, change its color, etc.
I found this code to approximately work:
public static void BoldSelectedText(RichTextBox control)
{
control.SelectionFont = new Font(control.Font.FontFamily, control.Font.Size, FontStyle.Bold);
}
But when I type in more letters in the RichTextBox the text is still bold.
How can I make it so that only the selected text is bold and the next characters aren't unless I select the text and hit the "Make Bold" button?
You should set the font after the selection to the original font.
If you want you can save the
SelectionStartandSelectionLengthand call theSelectmethod to select the text again.this way the text stays selected, and the font afterwards is still correct.