How to constantly scroll to the end of text in mul

2019-06-16 20:31发布

问题:

This question already has an answer here:

  • How do I automatically scroll to the bottom of a multiline text box? 11 answers

I'm updating my text box with text using a timer. Each time timer ticks I'm being redirected to the beginning to the text typed in my multiline text box.

How to do this?

回答1:

I'd say that when you refresh, you could move the selection cursor to the end, then scroll the textbox 'til it's visible using ScrollToCaret.

That'll be something like

 yourtextbox.SelectionStart = yourtextbox.Text.Length
 yourtextbox.ScrollToCaret()


回答2:

This works much better. It's better than Kotch's solution because there is no need constantly updating the position of cursor.

txtDisplay.AppendText(txtDisplay.SelectedText);


回答3:

Try using the TextBox.Select method:

textBox.Select(textBox.Text.Length, 0);

That will set the cursor to just past the last character in the text box.