RichTextBox Selection color problem
-
As short as i can explain... I have a RichTextBox that i want to use for syntax highlighting. For coloring i use: richControl.Select(...); richControl.SelectionColor= ...; and it works . The text is highlighted using a list of keywords. Lets say that I have te following line in my textbox: I like icecream In this line "like" is a keyword and its color is red(for explanation sake) and all the other words are black. THE PROBLEM is that if I move the caret just after the word "like" and I start typing, the new inputed characters will also be red,and i wanted them to be black. How can i escape this problem?
-
As short as i can explain... I have a RichTextBox that i want to use for syntax highlighting. For coloring i use: richControl.Select(...); richControl.SelectionColor= ...; and it works . The text is highlighted using a list of keywords. Lets say that I have te following line in my textbox: I like icecream In this line "like" is a keyword and its color is red(for explanation sake) and all the other words are black. THE PROBLEM is that if I move the caret just after the word "like" and I start typing, the new inputed characters will also be red,and i wanted them to be black. How can i escape this problem?
That's the regular behaviour you get in every text editor under windows that allows for formatted text. If you really want to do syntax highlighting in your RTB yourself (although there are several articles here on this topic), you should reconsider when to perform colorization. If you do it whenever the text is changed or when a key is pressed, then you'll find out that
like
+ the letter you typed isn't a keyword anymore, so the whole word should be black.Regards, mav -- Black holes are the places where god divided by 0...