textBox固定显示最后几行的时候滚动条老是在跳

封尘印 2011-09-16 04:02:16
outputScreen.AppendText(text);
int length;
length = outputScreen.TextLength;
if (length > 10000)
{
outputScreen.Text = outputScreen.Text.Substring(length - 10000));
}

当 总长度>10000后 每次截取最后10000个数据的时候, 滚动条总会跳到最上,只能手动设到最后 有没有办法给Text赋值的时候光标直接是在最后的?

或者有没有别的删掉textBox前面几行的办法?
...全文
168 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
封尘印 2011-09-21
  • 打赏
  • 举报
回复
最后改用richtextbox了, textbox在设置text时滑动块会自动跳到最上边, rechtextbox滑动块是自己设置位置的,不会乱跳.
封尘印 2011-09-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xuwei296 的回复:]

删除:outputScreen.Text = outputScreen.Text.Substring(0,10000));

跳到最后: outputScreen.Select(outputScreen.Text.Length, outputScreen.Text.Length);
outputScreen.ScrollToCaret();

欢迎加入,IT技术联盟……
[/Quote]

看错了, 还以为那行是要删掉不用-_-

试了一下, 当执行删除后, 滚动条还是会跳到最顶部, 虽然跟着马上就会跳到最底下, 不过还是可以看到滑动块在跳动
封尘印 2011-09-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xuwei296 的回复:]

删除:outputScreen.Text = outputScreen.Text.Substring(0,10000));

跳到最后: outputScreen.Select(outputScreen.Text.Length, outputScreen.Text.Length);
outputScreen.ScrollToCaret();

欢迎加入,IT技术联盟……
[/Quote]

这样改的话,没达到目的呀, 我是想当数据超过10000后, 删掉开始的几笔数据, 显示在textbox上面的保持10000
wnyxy001 2011-09-16
  • 打赏
  • 举报
回复

outputScreen.ScrollToCaret();

原来还有这个
wnyxy001 2011-09-16
  • 打赏
  • 举报
回复

outputScreen.Focus();
outputScreen.SelectionStart = outputScreen.Text.Length;

光标在最后但是滚动条还是在最上面
  • 打赏
  • 举报
回复

private void tb_Import_TextChanged(object sender, EventArgs e)
{
ChanageTextBox(this.tb_Import);
}
private void ChanageTextBox(TextBox tb)
{
tb.SelectionStart = tb.Text.Length;
tb.SelectionLength = 0;
tb.ScrollToCaret();
}
下一站轻风 2011-09-16
  • 打赏
  • 举报
回复
删除:outputScreen.Text = outputScreen.Text.Substring(0,10000));

跳到最后: outputScreen.Select(outputScreen.Text.Length, outputScreen.Text.Length);
outputScreen.ScrollToCaret();

欢迎加入,IT技术联盟:34683253
SZ201108130829 2011-09-16
  • 打赏
  • 举报
回复
可以用富文本框试一下

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧