Click here to Skip to main content
13,252,206 members (56,953 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 26 Jun 2009

Multiple Colored Texts in RichTextBox using C#

, 26 Jun 2009
Rate this:
Please Sign up or sign in to vote.
Multiple Colored texts in RichTextBox using C#



This article is created for making multiple colored texts in a textbox. By using the SelectionText property in richtextbox we have created a sample application for multiple colored texts in Microsoft’s richtextbox control. Let us see how to make it.


  1. .NET Framework 2.0
  2. Visual Studio 2005


Actually one of my colleagues asked me how to enter values in a richtextbox with multiple color texts.

I just tried to find any other way to have multiple colors in a textbox, unfortunately did not find one. Then I tried in Google and found that we have an option to do it in richtextbox. There is a property to set colored text by using SelectionText.

Richtextbox has the properties of SelectionFont, SelectionColor and SelectedText. Setting the values for these properties makes multiple colors in our richtextbox.

I just tried to create it as a sample application and it is done. It has a very simple logic to it. I have given the code snippet with this article. You can download the attached sample application and try to see the magic by clicking the buttons. There are two buttons available to test. One is for red colored text and the other is for green colored text. You can change the colors as per your wish by changing the codebehind.

Using the Code

The following code snippet explains to us how to do the multiple colored texts in textbox. Let us see:

Font font = new Font("Tahoma", 8, FontStyle.Regular);
richTextBox1.SelectionFont = font;
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = Environment.NewLine + textBox1.Text;		

Using the above code, I have created a sample application and attached it with this article (please see download link at the top of this article).


Hence we have made multiple colored texts in our richtextbox. This is basically used for making some chat application. We will have to show the text of the person at the other end in a different color in the chat application, so that we can use this method. We can create a simple method and call in every time we need to show the text in richtextbox with parameters like “textbox1.text, color, etc.”


  • 27th June, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
India India
Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.


visit my blog


I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
koolprasad200321-May-14 1:00
memberkoolprasad200321-May-14 1:00 
QuestionMessage Closed Pin
25-Jan-14 23:19
memberMember 1022174125-Jan-14 23:19 
GeneralMy vote of 5 Pin
Member 65974913-Feb-13 15:01
memberMember 65974913-Feb-13 15:01 
QuestionNice Pin
rafinhacsm23-Jan-13 7:37
memberrafinhacsm23-Jan-13 7:37 
SuggestionMulti colored text Pin
Darkuss19-Dec-12 9:35
memberDarkuss19-Dec-12 9:35 
QuestionProblems with 'previously selected' text. Pin
DigitalJedi8053-Oct-12 8:47
memberDigitalJedi8053-Oct-12 8:47 
QuestionWhat I needed. Pin
Member 1549283-Jun-12 6:21
memberMember 1549283-Jun-12 6:21 
GeneralLove! Pin
stag9224-May-12 8:36
memberstag9224-May-12 8:36 
GeneralMy vote of 1 Pin
SercanOzdemir10-Nov-11 4:42
memberSercanOzdemir10-Nov-11 4:42 
GeneralSimple but helpful information Pin
Edo Gasali7-Apr-11 23:52
memberEdo Gasali7-Apr-11 23:52 
GeneralMy vote of 1 Pin
gurisoft4-Mar-11 6:35
membergurisoft4-Mar-11 6:35 
GeneralRe: My vote of 1 Pin
DigitalJedi8053-Oct-12 8:52
memberDigitalJedi8053-Oct-12 8:52 
GeneralIf selecting in box Pin
ginbot27-Feb-11 10:26
memberginbot27-Feb-11 10:26 
GeneralRe: If selecting in box Pin
DigitalJedi8053-Oct-12 8:54
memberDigitalJedi8053-Oct-12 8:54 
GeneralMy vote of 1 Pin
ginbot27-Feb-11 10:21
memberginbot27-Feb-11 10:21 
GeneralRe: My vote of 1 Pin
DigitalJedi8053-Oct-12 8:55
memberDigitalJedi8053-Oct-12 8:55 
GeneralMulti Colors to Multi Texts in a Single Line Pin
Member 431902820-Jan-10 0:18
memberMember 431902820-Jan-10 0:18 
GeneralRe: Multi Colors to Multi Texts in a Single Line Pin
Ant210017-Jun-10 13:02
memberAnt210017-Jun-10 13:02 
GeneralRe: Multi Colors to Multi Texts in a Single Line Pin
GPUToaster19-Jun-10 20:44
memberGPUToaster19-Jun-10 20:44 
GeneralRe: Multi Colors to Multi Texts in a Single Line Pin
Ant210019-Jun-10 21:51
memberAnt210019-Jun-10 21:51 
GeneralMy vote of 1 Pin
Phil J Pearson23-Dec-09 0:55
memberPhil J Pearson23-Dec-09 0:55 
GeneralMy vote of 1 Pin
VMykyt16-Jul-09 21:56
memberVMykyt16-Jul-09 21:56 
GeneralMy vote of 1 Pin
VMykyt16-Jul-09 21:41
memberVMykyt16-Jul-09 21:41 
GeneralMy vote of 1 Pin
hoasidpfuaokjsñeirf2-Jul-09 3:36
memberhoasidpfuaokjsñeirf2-Jul-09 3:36 
GeneralMy vote of 1 Pin
Jon Artus1-Jul-09 5:54
memberJon Artus1-Jul-09 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 27 Jun 2009
Article Copyright 2009 by S.Vinothkumar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid