While I do know the above goal is rather challenging to achieve, I know it can be done.
What the one I made does:
It compares each word to a word from the list, if its a match, it will physically select the text and change the color, and finally it will return the carat to the position it was in when it highlighted.
Issues with this:
Flickering. It always flickers. I managed to reduce the flicker by making the thread sleep for 50 milliseconds, but I could not get rid of it entirely (it didn't noticeably slow down typing either). Now, another thing that I tried was using a second RichTextBox to have the highlighting occur to that, but that made no obvious differences at all.
Scrolling. It will scroll the RichTextBox if the amount of text is big enough to cause scrollbars to appear.
Deleting text. If you delete part of a word which has been highlighted, itll retain the color formatting even if the word is now changed. Itll also physically select the entire word, which baffles me endlessly.
Closing the window. Since the highlight subroutine is called whenever the RichTextBox's TextChanged event is called, apparently it is fired when the window closes? However, since the window is closing, it slows down the entire process, so with a larger file it may take 5-10 seconds to go through and highlight each keyword.
How can I solve each of these issues? I do not want to use someone else's component, I specifically want to use my own.
Thanks for the help, I have spent several hours on this and so far I am pleased with the results.
Some ideas I have had:
Physically edit the RTF instead of using a built in method for changing the text color, this would get rid of all my issues. Assuming a keyword was "The" (for example), what would the rtf be to make it turn blue?
Don't use syntax highlighting (last resort here)
My end goal: A syntax highlighter for a RichTextBox which works as well as the one in Visual Studio.
EDIT: Is there another component which would be better for this than a RichTextBox?