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 in below code.


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


By using the above code, we can make a multiple colored texts in our richtextbox. This is basically used for doing some chat application. We will have to show the other end of person’s text in different color in chat application. So that we can use this method. And we can create a simple method and calling in every time of showing the text in richtextbox with the parameters of like “textbox1.text, color,..etc”.

For more visit my article in codeproject here with more explanation.

...S.VinothkumaR.

1 comment:

Venkatesh said...

hi vinoth..
you have how to put colour to a line
which comes from the text box.

Can you help to change colour of lines in the rich text box which are already present in the rich text box