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

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

1. 在[设计模式]里双击TextBox(对应的name):
2. 在相应的cs文件中填入下面的code:

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

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

 

转到博客首页查看更多随笔

你可能感兴趣的:(WinForm)