Using The RichTextBox control

M

Marvin Scheinbart

I'm using a richtextbox to display formatted text. The problem is not
the formatted text but getting the richtextbox to display the text
properly. My program prints out messages to the user. I maintain all
user messages in the richtextbox so the user can have a history of
messages. When the richtextbox fills with text messages, all new text
messages get appended to the bottom of the existing text. These new
messages are not visible. I have to use the scroll bars to scroll down
to see the last messages written to the richtextbox.

How do I force the richtextbox to bottom (or top) justify the text
insertion so that all new messages written are always displayed? I want
the older message to scroll off the screen, not the new messages.


Thanks,

Marv
 
M

Marcos Stefanakopolus

I tend to need to do this sort of thing in the context of an event handler
that's passing me text from a worker thread. This is handy for giving your
program a quick-and-dirty "debug console" window:

public void UpdateDebugTextBox(object epitome, StringEventArgs e)
{
if(DebugTextBox.InvokeRequired)
{
this.BeginInvoke(new Epitome.EpitomeStringEvent(UpdateDebugTextBox),
new object[]{epitome, e});
}
else
{
DebugTextBox.AppendText(e.status); // e.status contains the string we
want to put in the richtextbox
DebugTextBox.Focus();
DebugTextBox.SelectionStart = DebugTextBox.TextLength;
DebugTextBox.SelectionLength = 0;
DebugTextBox.ScrollToCaret();
}
}
 

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