2008年11月20日星期四

Scroll TextBox programmatically

Today, one customer want to scroll the TextBox to the last line. It's easy to use hand, but a little bit hard if using code before we don't know how to do.

Sometimes, I think this requirment is very common for net work applications, if there are ports in the client and listen to the server and get information from the sever, and then display in the textBox. Actuall, the information will get displayed, but the scrollBar will not scroll even the height of the Text is above the height of the MultiLine TextBox.

Actually, it is very easy with the following code, we first move the caret to the last line, and use ScrollToCaret method to achieve the goal.
this.textBox1.Focus();
this.textBox1.SelectionStart = this.textBox1.Text.Length;
this.textBox1.ScrollToCaret();

没有评论: