views:

1317

answers:

2

I have a textbox with the .Multiline property set to true. At regular intervals, I am adding new lines of text to it. I would like the textbox to automatically scroll to the bottom-most entry (the newest one) whenever a new line is added. How do I accomplish this?

+8  A: 

You can use the following code snippet:

myTextBox.SelectionStart = myTextBox.Text.Length;
myTextBox.ScrollToCaret();

which will automatically scroll to the end.

GWLlosa
Looked here for the answer, couldn't find it, so when I figured it out, I figured I'd put it up here for future users, or if maybe someone else had a better approach.
GWLlosa
Thanks, It works as my expectation.
Minh Le
A: 

Try to add the suggested code to the TextChanged event:

private void textBox1_TextChanged(object sender, EventArgs e) { textBox1.SelectionStart = textBox1.Text.Length; textBox1.ScrollToCaret(); }

Tommy Engebretsen