Help - Search - Members - Calendar
Full Version: Changing Text Colours.
Sal's RuneScape Forum > Everything... Not RuneScape > Tech Talk > Programming & Web Development
Samarkov
How can I change the colours in my scripting language's compiler like in Visual Basic?
I have a few words I will reserve as script-only words and I need a way to display what they are.

Here's an example of what I want to accomplish:


Thanks!
~~Samarkov king.gif
Roy
Tools > Options > Environment > Fonts and Colors

There you can select a type of word and give it another (background) color or make it bold.
Samarkov
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 king.gif
Roy
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 king.gif

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]
Samarkov
QUOTE (Roy @ Sep 4 2009, 10:03 AM) *
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 king.gif

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]



Thank you very much! I did the same basic idea as you the first time I tried this, but I forgot to add code that makes everything else black.

Thanks a bunch!
~~Samarkov king.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.