user1158745 user1158745 - 1 year ago 98
C# Question

Rich Text box scroll to the bottom when new data is written to it

My program calls Java and then redirects stdout to a

. My problem is that the vertical scrollbar always stays at the top of the box every time data is written.

Even if you scroll to the bottom, once new data has been written it goes to the top. I would like the opposite.

So when new data is written, it stays at the bottom. How can I do this?

Answer Source

Yes, you can use the ScrollToCaret() method:

// bind this method to its TextChanged event handler:
// richTextBox.TextChanged += richTextBox_TextChanged;
private void richTextBox_TextChanged(object sender, EventArgs e) {
   // set the current caret position to the end
   richTextBox.SelectionStart = richTextBox.Text.Length;
   // scroll it automatically
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download