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
2009-05-22 14:58:50
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
2009-05-22 14:59:44
Thanks, It works as my expectation.
Minh Le
2009-07-10 03:25:20
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
2009-08-29 08:49:04