Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

22. Windows Forms RichTextBox

22.4 How do I set the color and font in a RichEditBox?


You use the SelectionFont and SelectionColor properties. Make sure the control had focus. Then the following code will set the currently selected text to a red-bold-courier font. If no text is currently selected, then any new text typed (or inserted) will be red-bold-courier.

[C#]
     richTextBox1.Focus();
     richTextBox1.SelectionColor = Color.Red;
     richTextBox1.SelectionFont = new Font ("Courier", 10, FontStyle.Bold);

[VB.NET]
     richTextBox1.Focus()
     richTextBox1.SelectionColor = Color.Red
     richTextBox1.SelectionFont = new Font ("Courier", 10, FontStyle.Bold)