开发者

How can I scroll to the top of my textbox after printing some text to it?

开发者 https://www.devze.com 2023-03-23 21:18 出处:网络
I am printing a lot of text to a textbox an开发者_如何学运维d would like it to scroll to the top after the printing is complete.Set the SelectionStart = 0; for your TextBox. See here at MSDN about Sel

I am printing a lot of text to a textbox an开发者_如何学运维d would like it to scroll to the top after the printing is complete.


Set the SelectionStart = 0; for your TextBox. See here at MSDN about SelectionStart. You can then set your SelectionLength = 1;

You can then call ScrollToCaret.


textbox.SelectionStart = 0;

that works in Wpf and in WinForms Applications


For WinForms, use a combination of SelectionStart = 0 and ScrollToCaret()


Just use navigation keys after making sure the control has focus:

SendKeys.Send("^({HOME})");
SendKeys.Send("^({END})"); 

etc. as needed


SelectionStart = 0 did not work for me.

I used richTextBox1.Clear(); before loading new text.

0

精彩评论

暂无评论...
验证码 换一张
取 消