Problems with Colors in a RichTextBox

Joined
May 20, 2006
Messages
7
Programming Experience
Beginner
:confused:

Hello!

I'm having problems with a richTextBox. This rich is used like a code editor (with some words in blue and the oders in black) The user can write on it new words and after that he can push a button that read all the rich and paint (If it's necessary) the new words. Here, I've two big problems:

1- If some word is Blue, and the user try to write near it, the new characters writed are blue! I can't force (Well, I don't know) that all the characters that the user can write would be blacks.

2- Is possible to change all the words to black with some easy process or trick. Read all the words another time painting its manually to black isn't a good way :(

Thanks in advance.
 
You suppose to realize 1st the key words and only make the method which would search those words and colorize to blue or any other color. About the 2nd Q ..how to make all the text in black it's very easy: just remove the handler of the method that brings color to the keywords and add this line:

Me.RichTextBox1.ForeColor = Color.Black

then back/add the handler again ;)
 
Sorry, but my English is a little poor, and I can't understand very well :(

1- I don't understand this solution. My problem is that when the user are writing, I want that ALWAYS the color has to be black (and if the user writes near a blue word, the chars tha appear when he writes are blue too!)

2- I try to do it, but I think there's something that I'm doing wrog because It doesn't work.
I want that when the user writes on the richTextBox all the words changed to black. I try it with this (thanks to you code):

VB.NET:
 Private Sub richActual_KeyPressed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles richActual.KeyPress
        'richActual.SelectAll()
        'richActual.SelectionColor = Color.Black
        richActual.ForeColor = Color.Black
End Sub

Thanks in advance
 
Back
Top