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

后端 未结 6 967
天命终不由人
天命终不由人 2020-12-05 22:43

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 i

6条回答
  •  天涯浪人
    2020-12-05 23:09

    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();
    }
    

提交回复
热议问题