[quoted text, click to view] > Hello, I've RichTextBox with quite long text (thousands of lines) and I'm
> doing something line syntax coloring. I set different colors to each word,
> number etc. with selecting the text (Select()) and the setting
> SelectionColor. But it's very slow. I even tried to send the messages
> manually and avoid the calling of SelectionColor (that's the slowest thing)
> but it's not much better. How to do this effectively?
I don't think there is a way to get good performance with the RichTextBox
methods. I think the reason is that every highlight operation you do results
in reconstituting the RichTextBox's .rtf field which is a very large string
if you have thousands of lines. Selecting text can also be costly if you are
using SelectionColor and/or SelectionBackColor.
To get good performance with a RichTextBox, you could build the rtb's .rtf
field (using stringbuilder) in one pass over the rtb's text looking for
things to highlight. The prerequisite is coming to terms with the MS RTF
specs and how they are used in a RichTextBox. Or you could try (trial and
error) the win32 apis and messages like EM_SETCHARFORMAT. Or maybe you could
use InkEdit which is supposed to be a superset of RichTextBox. All sound
daunting to me.
Maybe there is an alternative to RichTextBox, but I don't know what it is.
Sorry there is no good news in this post.