How to prevent TextBox auto scrolls when append text?

后端 未结 2 1474
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 04:58

I have a multi-line TextBox with a vertical scrollbar that logs data from a realtime process. Currently, whenever a new line is added by textBox.AppendText(), the T

2条回答
  •  悲&欢浪女
    2021-02-04 05:24

    You have to do it something like this,

    textBox1.AppendText("Your text here");
    // this selects the index zero as the location of your caret
    textBox1.Select(0, 0);
    // Scrolls to the caret :)
    textBox1.ScrollToCaret();
    

    Tested and working on VS2010 c# Winforms, i dont know about WPF but google probably has the answer for you.

提交回复
热议问题