Result of RichTextBox.AppendText of too many characters?

R

Ray Mitchell

Hello,

I have a multiline RichTextBox that I use for data logging. I'm concerned
about how the AppendText method reacts when over time the maximum number of
characters have been added. Do the oldest characters it contains start
rolling off the top into the bit bucket, does it simply start silently
ignoring appends until some characters, are deleted, or does some kind of
exception get thrown? I've heard numerous opinions on what the maximum
character count can be and I can implement an algorithm to deal with this
issue if necessary. But if nothing "bad" happens, I'd prefer not to
introduce the extra complexity.

Thanks,
Ray
 
D

Duggi

Hello,

I have a multiline RichTextBox that I use for data logging.  I'm concerned
about how the AppendText method reacts when over time the maximum number of
characters have been added.  Do the oldest characters it contains start
rolling off the top into the bit bucket, does it simply start silently
ignoring appends until some characters, are deleted, or does some kind of
exception get thrown?  I've heard numerous opinions on what the maximum
character count can be and I can implement an algorithm to deal with this
issue if necessary.  But if nothing "bad" happens, I'd prefer not to
introduce the extra complexity.

Thanks,
Ray

I think you should write a event that would be fired when RichTextBox
size goes beyond the expected size. If you do not want to write a
separate control, in the text changed event, keep checking the size of
the RichTextBox.

In this way you can delete the first bunch of text to acomidate the
new text for log.

Try the following code snippet

const int DEFINEDLENGTH = 100;
const string LOGFILESPATH = @"C:\1.txt";

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (richTextBox1.Text.ToString().Length > DEFINEDLENGTH)
{
richTextBox1.SaveFile(LOGFILESPATH);
richTextBox1.Text = "";
}
}

-Cnu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top