Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple text color in rich text box

I can find a million examples of doing reg ex to apply syntax highlighting to a rich text box. but what i need it just a simple way to add in a word of a diffrent color.

What would the code be to just put the words "Hello World" into a textbox and have Hello be red and World be green?

This code doesnt work.

this.richTextBox1.SelectionColor = Color.Red
this.richTextBox1.text += "Test"
like image 615
The Digital Ninja Avatar asked Dec 02 '22 06:12

The Digital Ninja


2 Answers

This code adds text "Hello" in red color and "World" in green to the RichTextBox.

RichTextBox1.SelectionColor = Color.Red
RichTextBox1.SelectedText = "Hello "
RichTextBox1.SelectionColor = Color.Green
RichTextBox1.SelectedText = "World"
like image 123
Meta-Knight Avatar answered Dec 11 '22 03:12

Meta-Knight


Select the text after you put it in and then change the color.

For example:

richTextBox1.Text += "Test"
richTextBox1.Select(richTextBox1.TextLength - 4, 4)
richTextBox1.SelectionColor = Color.Red
like image 36
SLaks Avatar answered Dec 11 '22 05:12

SLaks