Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

My program calls Java and then redirects stdout to a RichTextBox. 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?

like image 879
user1158745 Avatar asked Feb 23 '12 16:02

user1158745


People also ask

What is the role of rich text box in C#?

The RichTextBox control enables you to display or edit flow content including paragraphs, images, tables, and more. This topic introduces the TextBox class and provides examples of how to use it in both Extensible Application Markup Language (XAML) and C#.

What is a rich text box?

In C#, RichTextBox control is a textbox which gives you rich text editing controls and advanced formatting features also includes a loading rich text format (RTF) files. Or in other words, RichTextBox controls allows you to display or edit flow content, including paragraphs, images, tables, etc.


1 Answers

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    richTextBox.ScrollToCaret(); } 
like image 128
Omar Avatar answered Oct 03 '22 03:10

Omar