Pete --
Your advice arrived while I was responding to earlier comments. I have
a major guilt issue here in that I over simplified my task in the hope
of learning more about the inner workings of the RichTextBox. (Not too
deep, I'm just learning!) In doing so I have cheated myself out of
receiving help at my project's structural level. I am essentially
splitting a byte array into lines and storing these lines in an
ArrayList. I then populate the RTB from the ArrayList.
I had to stress test this ArrayList - buffering logic repeatedly to
remove the off-by-one errors. I had a few in there ... but that part
is confirmed to be working! :)
And the bigger picture is I am building a viewer of large data files
that loads only the area of interest and does not hog memory
resources. Often my data files exceed 50 MB.
The ArrayList is a working buffer ... but it feeds the RTB which is
its own buffer too. This double buffering is inefficient of resources.
It works, it's relatively fast, but it also reflects my sloppy design.
Additionally, I Clear() the RTB each time I append or insert data into
the ArrayList buffer and then reload the RTB text.
I never learned MFC nor windows programming until now. Although I have
done a ton of numerical analysis type work. I do recall from Petzold's
Programming Windows 95 text that he moved a screen up a line and then
painted the new line when scrolling. For me to now Clear() the RTB and
rebuild it each time makes me feel like I am sloppy! I'd like to work
directly with the RTB buffer and eliminate the ArrayList if possible.
If I could insert and append into the RTB buffer beyond the viewing
area ... my thoughts are that I'd be taking advantage of what I
perceive to be very efficient RTB scrolling control.
Thanks for you input. It is always valuable!! I had not used the Lines
property as you illustrated. It's in my crosshairs now and I will
learn as I experiment with it. :)
-- Tom
>While the suggestions to process the Text property directly will work,
given what you're trying to do I think that accessing the text via the
Lines property would be easier. It basically does the String.Split() for
you, returning an array of strings, one per line. So:
void RemoveLine(TextBox box, int line)
{
string[] lines = box.Lines;
Array.Copy(lines, line + 1, lines, line, lines.Length - line - 1);
lines[lines.Length - 1] = null;
box.Lines = lines;
}
or something like that...my apologies if there's an off-by-one error. I
didn't actually compile or run the code. :)
Pete