I’m currently developing a very simple app with very basic syntax highlighting in a RichTextBox.
It works almost fine. What I’m doing is:
- Lookup a list of predefined regex if one or more matches.
- Select the match, applying the right style to the selection.
- Then replace the cursor where it initially was.
This method gets triggered on every KeyUp event. And it makes a LOT of flickering.
So my question is: how could I subtly highlight the text that I type without any flickering? This editor will never contain thousands lines of text, maybe about a hundred max so I don’t need any very optimized solution yet.
I tried some of the solutions proposed on other posts, but nothing interesting worked. And I don’t want to use another component from another library — I wanted to do it myself for learning purposes.
I decided to try something and it worked amazingly!
I’m highlighting one line at a time. So when the keyUp gets triggered I only parse the selected line. So NO flickering!
And at the startup I made a HighlightLines() method that loop through the lines and call my HighlightLine(lineIndex) method.
I’ll try to mix my solution with Cheeso’s and I guess it’ll make something awesome!
Thanks