C# – How to scroll down in a textbox by code in C#

cscrolltextboxwinforms

I am using winforms, and I update a text box once in a while (showing messages).
however, when the text reaches the end of the box it produces scrollbars and I don't know how to scroll down to the bottom. The only thing I see is ScrollToCaret, but Caret is at the beginning of the text. What is the command to scroll?

Best Answer

You can do this by making use of a function called ScrollToCaret. You need to first set the caret position to the end of the text box, then you can scroll to it. Here's how to do it:

        //move the caret to the end of the text
        textBox.SelectionStart = textBox.TextLength;
        //scroll to the caret
        textBox.ScrollToCaret();