Rich Text Box control in C# Win Forms

 

RichTextBox control is used to display text in specific format. That means by using Rich Text Box control we can apply the Fore Color, Back Color, Font size....etc.

 

Here we discuss about various formatting options available by using RichTextBox control. Create C# windows application => add RichTextBox control.

 

Apply the formats to text using Rich Text Box control as shown below.

 

using System;

using System.Drawing;

using System.Windows.Forms;

 

namespace RichTextBoxExp

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            richTextBox1.Font = new Font("Arial", 12f, FontStyle.Bold);

 

            richTextBox1.BackColor = Color.Yellow;

            richTextBox1.ForeColor = Color.Blue;

            richTextBox1.SelectionBackColor = Color.Red;

           

            richTextBox1.AppendText("This is Rich TextBox");

        }

    }

}

 

As shown above we mention the font size by using Font property. Through BackColor property we can mention the back ground Color. By using ForeColor we can mention font color. With the help SelectionBackColor property we can mention the back color for selected text.

 

Once you run the application, the output is as shown below.

 

                                                                                                                       

                                                                                                          RichTextBoxExp.zip (39.26 kb)