views:

58

answers:

3

I have a program where I basically need to load Rich Text from a StringBuilder. The problem is, somethimes I get a string that is 100,000 lines long (and this is a possible situation for the program), including Rtf codes and colours.

The problem isn't building the string, it's when I asign the Rtf property to the StringBuilder.ToString(), it takes a solid 4 minutes to load.

TextBox.Rtf = Build.ToString();

If I copy this same string from the StringBuilder, and load it in WordPad, it takes about 2 or 3 seconds. I am diabling the RTB's redrawing by using SendMessage() and WM_SETREDRAW, but that doesn't change anything.

Any suggestions?

A: 

Sorry, but the RTB control is not gonna cut 10,000 lines, nevermind 100,000.

One possible way to optimize it, is to load from a file or stream instead, but I dont suspect much improvement.

leppie
Then how does WordPad do it in 2-3 **seconds**?
Miguel
@Miguel, I suspect WordPad does not use an RTB control.
Dour High Arch
A: 

Just a guess, but could it be that the GC (garbage collector) gets triggered? That shouldn't last 4 minutes though...

Michel de Ruiter
A: 

RichTextBox Use the riched20.dll wich is the v3.0 of the library Rich Edit Control of microsoft. WordPad Use the msfedit.dll wich is the v 4.1.

The V4.1 is about 30 times more fast than the v3.0.

See this for more informations about versions MSDN About Rich Edit Controls

Polo