Rich Text box scroll to the bottom when new data is written to it

后端 未结 6 916
天命终不由人
天命终不由人 2020-12-05 22:43

My program calls Java and then redirects stdout to a RichTextBox. My problem is that the vertical scrollbar always stays at the top of the box every time data i

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 23:08

    The RichTextBox will stay scrolled to the end if it has focus and you use AppendText to add the information. If you set HideSelection to False it will keep its selection when it loses focus and stay auto scrolled.

    I designed a Log Viewer GUI that used the method below. It used up to a full core keeping up. Getting rid of this code and setting HideSelection to False got the CPU usage down to 1-2%

    //Don't use this!
    richTextBox.AppendText(text);  
    richTextBox.ScrollToEnd();
    

提交回复
热议问题