如何使Winform的Textbox滚动条保持在最后

来源:互联网 发布:java jar getresource 编辑:程序博客网 时间:2024/06/04 08:13

 

Winform编程中,使用的Textbox控件,我们很有可能会遇到需要随时更新其内容(比如聊天窗口文字的更新),当内容过多的时候,就会出现滚动条,如何让滚动条时刻跟随内容的最下面内容呢?

 

private void TextBox_TextChanged(object sender, System.EventArgs e)
{

    
this.TextBox.SelectionStart = this.TextBox.Text.Length;
    
this.TextBox.SelectionLength = 0;
    
this.TextBox.ScrollToCaret();
}
搞定。

原创粉丝点击