How to constantly scroll to the end of text in multiline text box? [duplicate]

别说谁变了你拦得住时间么 提交于 2020-01-14 07:37:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!