Nefzen Nefzen - 1 year ago 165
C# Question

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

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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download