Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you prevent a multiline textbox from scrolling when text is added?

I have a multiline TextBox called Console. While running, this textbox is being filled up with some communications data. I use

TextBox.AppendText("txt\r\n");

to add a line to it and that allows me to have it autoscroll down. My problem is I want to be able to not have it autoscroll down. So I thought I would try

TextBox.Text += "text";

But that scrolls you to the beginning of the box. My latest attempt was to use TextBox.SelectionStart to save the position before I wrote and restore it back to that after, but that didn't seem to make a difference and still brings me back to the beginning of the text.

int txtPosition = Console.SelectionStart;
Console.Text += "TextToAdd";
Console.SelectionStart = txtPosition;

Ideally I want to just be able to have the box stay where ever it happens to be and not scroll to the beginning or end of the text.

like image 762
Andy Avatar asked Oct 27 '25 04:10

Andy


1 Answers

I think you need to you a richtextbox instead of a generic textbox and this will provide you with the functionality you desire.

Enjoy!

like image 147
Doug Avatar answered Oct 30 '25 08:10

Doug