Suspend and resume layout only affect resizing and redrawing of controls, from what I got out of my experimenting with it this afternoon.
It turns out, the original method using the RichTextBox.Find is still faster than the char-by-char method, but not because of calculation time.. The actual char by char writing to the RichTextBox, whether visible, disabled, suspended, or not, is incredibly slow.
I can load a huge file into the RTB in almost no time using standard streamreader read methods, but char by char it's way too slow. I did some testing with my parsing method, and if I use special characters to define where colors would stop and start, rather than actually coloring/writing them to the RTB, and write that string to the RTB all in black, the text loads at what is not noticably any slower speed.
Conversely, if I read in the strings one line at a time, and add them to the RTB one character at a time, it's pretty much the same speed as it is when I am writing the formatted text one char at a time.
So, is there a way, to build a Rich Text string with formatting, and write it line-at-a-time to the RTB? I think if I could do that, the speed would go right up where I want it.
And, after doing one the slow way, I saved it to an RTF file, and viewed it with notepad. I can see all the formatting, and so on, so I thought I would try to build the formatted strings and insert them using the RichtTextBox.Rtf method instead of using SelectedText. Unfortunately, I get a file format error every time I try to insert a string I'm gonna keep playing with it and see what I can do..
OK, so that worked well. now that I've figured out how to format RTF text (and not have pieces vanish?!@#) It's good and fast. Only one problem.
RTF codes use our friend the backslash : \ to signify that there are functions coming. So, if I want to actually have that character displayed, I have to send \\. No big deal, just like C# actually. The problem comes in with the string quotes being colored in certain cases.
for example:
string myString = "\"Bill\""; would in C#set Bill to the value "Bill". So if my state is switched off at the first escape sequence for the quote, Bill would be black, rather than red.
i.e,
string myString = "\"Bill\"";
A more serious problem occurs if there is only one of these in a string, like this:
string mystring = "\" <- Thats the quote";
Where that string would translate to : " <-Thats the quote. Since there are an odd number of " in there, the first one would set it would look like this:
string myString = "\" <- Thats the quote";
nextline.programming = still.red;
etc,etc
until I hit another "
So, I thought I'd be smooth and say, OK, don't turn off the quote mode if this quote is proceeded by a \. Well, that fixed 90% of the problem, but now I have another problem.
This is a valid string in C#:
string myPath = "C:\\Documents and Settings\\Administrator\\";
So, when the parser hits that last quote, it's now being ignored because the \ is in front of it.
Instead of looking back, I say when you hit a \ inside of a quote, note it. It always indicates that an escape is coming. So you automatically know the next char is escaped and you can ignore it for rules, so something like this:
Man, this crap's always harder than it looks. Damned C# Flexibility. Now I need to handle the @ symbol somehow too. Because, this is also a legal string..
string bill = @"\Bill\";
I guess if the @ character is seen, I can just go by the straight quotes, ignoring the escape characters (because in C# the escape \" isn't valid when you have the @ in front of it..)
Sweet, so it looks like I'm done with this part of the deal, unless you can think of another way to break it.
Bill
Last edited by conipto; Nov 19th, 2005 at 10:18 PM.