Tuesday, September 4, 2018

C# - How to add formatted text to RichTextBox

richTextBox1.Clear();

richTextBox1.SelectionFont = new Font( "Courier New", 10, FontStyle.Bold );
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "This ";

richTextBox1.SelectionFont = new Font( "Courier New", 15, FontStyle.Bold );
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "is ";

richTextBox1.SelectionFont = new Font("Courier New", 20, FontStyle.Bold | FontStyle.Italic);
richTextBox1.SelectionColor = Color.Green;
richTextBox1.SelectedText = "a text";
Output:

No comments:

Post a Comment