QUOTE (Samarkov @ Sep 4 2009, 03:57 PM)

QUOTE (Roy @ Sep 2 2009, 05:28 AM)

Tools > Options > Environment > Fonts and Colors
There you can select a type of word and give it another (background) color or make it bold.
Not this, I mean being able to change certain word's colours in a textbox in my program. I've only been able to change the entire textbpx's forecolour, but is there a way to change the colour of certain words?
~~Samarkov

O like that... For that you'll need a richtextbox (not a normal textbox). If you're going to add text and give it color when you add it you can use this:
CODE
RichTextBox1.SelectionColor = Color.Red
RichTextBox1.AppendText("this will be red")
RichTextBox1.SelectionColor = Color.Black
RichTextBox1.AppendText(" and this will be black again")
This will give something like this int he richtextbox:
this will be red and this will be black again
You probably are used to just taking the string of the textbox, adding another piece of string to it and send it back but that won't work for some reason here. If you already have some text in it and you want to have a specified piece of text in a color:
CODE
RichTextBox1.AppendText("There's already some text here and the first five chars are red")
RichTextBox1.Select(0, 5)
RichTextBox1.SelectionColor = Color.Red
This will make the first 5 characters of the textbox red.
There's already some text here and the first five chars are red
So if you want to make a specific word red, find its startindex in the string, its length and use those in the select command.
I used that first piece of code in a program of mine and the result looks good doesn't it?
Spoiler: Click to Toggle the Spoiler.
[Close]