Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting text color in text box C#

Tags:

c#

winforms

I have a multi line text box which is used to display the status messages of the operations that I do in the application. I want to set separate colors for different lines in the text box. If I use the ForeColor property, it sets the color of all the text. I want to set the color of a single line. How can I do this?

Thanks, Rakesh.

like image 677
Rakesh K Avatar asked Dec 27 '22 18:12

Rakesh K


1 Answers

You need to use the RichTextBox instead. You can then use the properties SelectionStart, SelectionLength, and SelectionColor to achieve what you want, as the easiest solution. You can also modify the RTF directly. You can actually just edit the designer code and change System.Windows.Forms.TextBox references to RichTextBox, then make some small modifications to your code.

like image 103
David Anderson Avatar answered Jan 09 '23 08:01

David Anderson