FastColoredTextBox (FCTB) does provide StringBuilder-like methods, for example there is
public virtual void AppendText(string text, Style style)
and similar methods. However, it treats each of these as user input: each action is added to the undo history.
I am building my text programmatically, it is data fields and text, along with all the formatting and styles, and it gets large. At the end I throw away that undo history (or set the control to read only). A lot is wasted in memory and computation time. It takes a few seconds before the control is usable.
So is there a way to build my text before passing it to the FCTB?
Create a
TextSource-derived class:Add this virtual method to the
TextSourceclass:In the FCTB class, add this line to the
InitTextSourcemethod:Change the
Charconstructor for convenience:Use as follows:
If you want to do it without recompiling FCTB you can just create the
TextBuilderclass minus virtual method etc. and callb.OnTextChanged(0, b.Count - 1)after assigningTextSource.