---
title: "RichTextBox Control in C#.Net"  
description: "RichTextBox Control in C#.NetWhereThe RichTextBox control enables text to be displayed with formatting in plain text or rich-text format (RTF).  It"  
author: "Anonymous User"  
published: 2011-01-24  
updated: 2020-07-14  
canonical: https://www.mindstick.com/articles/416/richtextbox-control-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# RichTextBox Control in C#.Net

## RichTextBox Control in C#.Net

WhereThe RichTextBox control enables text to be displayed [with formatting in plain text](https://www.mindstick.com/articles/853/writing-data-to-excel-sheet-using-c-sharp) or rich-text format (RTF).\

It also provides the facility to save the text in the file and restore it from a file.

Drag and drop RichTextBox control from the toolbox on the window Form.

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/e287cac9-07f9-4eeb-9a41-e9ff23ae586d.png)\

#### Write the Text in RichTextBox

```
private void frmRichTextBox_Load(object sender, EventArgs e){            // write textin RichTextBox            richTextBox1.Text= "Hello How are you";}
```

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/d83be127-b37a-441d-8dd1-6e5e0f284710.png)

#### Change ForeColor of text written in RichTextBox

In RichTextBox each text can be in a different color.

##### Code:

```
private void frmRichTextBox_Load(object sender, EventArgs e)        {            //Find method is used to find the text written in RichTextBox            richTextBox1.SelectionStart= richTextBox1.Find("Hello");            richTextBox1.SelectionColor= Color.Red;            richTextBox1.SelectionStart= richTextBox1.Find("How are you");            richTextBox1.SelectionColor= Color.RoyalBlue;         }
```

#### Run the Project

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/6761bc79-0577-4a75-b12b-6f74a86cdd04.png)

#### Save RichTextBox Text into File and Restore from File

##### Code:

Write code in the click event of the button. When you double click on click event then click event handler will create in .cs file.

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/d3da9fa9-4328-4635-af76-d618183eaf9c.png)\

```
private void btnSave_Click(object sender, EventArgs e){     //SaveFile Method Saves the contents of the RichTextBox into a file     richTextBox1.SaveFile("h1.rtf");}private void btnLoad_Click(object sender, EventArgs e){  //LoadFile Method Loads the contents of a file into the RichTextBox control     richTextBox2.LoadFile("h1.rtf");}
```

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/c7956ae7-7657-4b6f-94af-f621f385e4f0.png)

When you click save button then text written in RichTextBox1 will save to the specified file.

When you click the Load button then contents of a specified file Load into the RichTextBox2.

![RichTextBox Control in C#.Net](https://www.mindstick.com/mindstickarticle/96db62ec-fe50-4a8b-b1ad-37ff19856dbb/images/4ffb26f6-d45c-4dbc-ad96-2a87bb045240.png)

---

Original Source: https://www.mindstick.com/articles/416/richtextbox-control-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
