读书人

C#怎样使TextBox里内容更新时它的垂直

发布时间: 2012-02-14 19:19:19 作者: rapoo

C#怎样使TextBox里内容更新时它的垂直下拉条自动处于最下方(效果要好)
我用的是这种方法:

private void textBoxInfo_TextChanged(object sender, EventArgs e)
{
textBoxInfo.SelectionStart = textBoxInfo.Text.Length;
textBoxInfo.ScrollToCaret();
}

但是这个TextBox的内容刷新很快(每秒增加100行内容)

而且没次增加内容时,下拉条会先跑到最顶部,然后才跑到最底部
想想,每秒100次,仅滚动条来回移动就很Hao CPU。。。

有没有方法让滚动条一直处于最底部,
而TextBox.text 加内容时,滚动条不出现“跑到最顶部”这个动作呢?

WinForm程序

[解决办法]
不要在TextChanged事件里面写代码,不要直接修改Text属性值,试试这个。

textBoxInfo.AppendText(TextInfo);
textBoxInfo.SelectionStart = this.txtOutput.TextLength;
textBoxInfo.ScrollToCaret();

读书人网 >C#

热点推荐