Friday, April 8, 2011

How to scroll to bottom in a textbox in C#

Use function called ScrollToCaret of textbox. You need to first set the caret position to the end of the text box, then call the ScrollToCaret function.
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();

2 comments:

  1. How do you do this in a program that has multiple threads though?

    ReplyDelete
  2. @Past Expiry
    Can u send me the code? Get the textbox in the current thread and set the position.

    ReplyDelete