RE: Effective coloring in RichTextBox



Making RTF code by hand appeared on my mind, but that's what I didnt want to
do.
InkEdit isn'a solution. Quote from msdn library:
This control is a superset of the RichTextBox control. It extends the
RichTextBox control with the ability to capture, recognize, and display ink.
The selection is quite fast, i commented the coloring line, and it all took
3s, which is good. I played with the messages, but as I wrote it made it
faster only a little bit more.

Any more ideas?
--
Jakub Cermak


"AMercer" wrote:

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.

.



Relevant Pages

  • Re: Inserting contents of Word document into a richtextbox control
    ... As you've discovered the RTF control expects an RTF ... >richtextbox text as the activedocument contents but this is too clumsy ... After searching in groups I realised that Word doesn't use ...
    (microsoft.public.word.vba.general)
  • Re: Rich Text parsing with RichTextBox
    ... > color from the RTF strings. ... > RichTextBox doesn't seem to be able to understand my RTF. ... > rich text control. ... > SelectionColor still returns Color.Empty. ...
    (microsoft.public.dotnet.framework)
  • Re: How to load rtf in richtextbox with header and footer
    ... RTF codes that specify a header and footer to work inside a RichTextBox? ... That _does_ operate basically on a page level, and if you embed it into your own control that could produce the visual results you're looking for. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Effective coloring in RichTextBox
    ... manually and avoid the calling of SelectionColor ... I don't think there is a way to get good performance with the RichTextBox ... in reconstituting the RichTextBox's .rtf field which is a very large string ... To get good performance with a RichTextBox, you could build the rtb's .rtf ...
    (microsoft.public.dotnet.framework.windowsforms)
  • RE: Initializing a RichTextBox
    ... The Rtf property of RichTextBox gets or sets the text of the RichTextBox ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)

Quantcast