Reputation: 8515
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.
Upvotes: 4
Views: 6072
Reputation: 4949
TextBox control doesn't support coloring of intermediate lines. use ListView instead. You can achieve a similar look-and-feel by using "Details" or "List" View mode.
Upvotes: 2
Reputation: 4142
You have to use a richtextbox for this. You can specify all sorts of formatting inline with your text
Upvotes: 0
Reputation: 20162
TextBox does not support multiple colors (or fonts or sizes). You'll have to use RichTextBox.
Upvotes: 0
Reputation: 13690
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.
Upvotes: 7
Reputation: 66397
You can't do that with the built in control.
Either inherit it and create your own control, or use something like this:
Background color of a ListBox item (winforms)
In there it's background color but you can same way apply different fore color.
Upvotes: 1