问题
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.
来源:https://stackoverflow.com/questions/8917067/how-to-constantly-scroll-to-the-end-of-text-in-multiline-text-box