Tag Archives: scroll

Scroll to the bottom of a multiline textBox in C# (WinForms)

There is sometimes that you’re building an application in C# (WinForms) and you want to use a text box control as log output. Is it in that case when you find that every time the textbox gets updated, you have to scroll all the way down to see the last added line.

This is definitely an annoying behaviour. There are a couple ways to solve it.

The first one, is to update the textBox with TextBox.AppendText(string text), which leads you to properly solve this inconvenient. I.E.:

Note the Environment.NewLine for the carriage return after adding the text to append (\r\n)

The second one is to use the next snippet:

Which results in the same result.

These two solutions will not work if they are called before the textbox is shown, or if the textbox is not visible (i.e. in a different tab of a TabPanel). See TextBox.AppendText() not autoscrolling. This may or may not be important, depending on if you require autoscroll when the user can’t see the textbox.

One way to solve this, is to perform additional scrolling on the VisibleChanged event:

Check this QUESTION from StackOverFlow for an extended explanation.