Text Coloring

Topics: Developer Forum
Apr 3, 2014 at 8:41 PM
Edited Apr 3, 2014 at 9:43 PM
Hi

I am trying to Color the text.
when I select text I can get the text to change color, but as soon as I click somewhere else its gone.

I want to be able to keep the coloring, But i dont need to be able to save the coloring.
I haev tried this.
scintilla1.Selection.ForeColorUnfocused = Color.Red;
scintilla1.Selection.ForeColor = Color.Green;

but this isn't working, as I loose the text coloring
Coordinator
Apr 20, 2014 at 11:01 PM
Sounds like you're fighting against a lexer. A lexer's job is to basically detect when the text has changed (or window is painted) and update the color accordingly. If you've accidentally (or intentionally) set the control to use a lexer, it might be what's causing your changes to get overwritten.

The best way to do custom coloring is to set the lexer to Container and handle the StyleNeeded event. This event fires every time Scintilla thinks the colors should be updated (because of changes, etc...). In that way you are working with the lexer instead of against it.

If you don't feel like you need to go so far as handling the event and just want to occasionally do some custom coloring, then you'll want to make sure the lexer is not set or is set to Null.



Jacob
Marked as answer by jaqalou on 4/22/2014 at 6:44 AM