A multiline textbox implements the method ScrollToCaret(). This should be used in combination with AppendText(string text).
Suppose we have a textbox called textBox1:
Code:
private void textBox1_TextChanged(object sender, EventArgs e) {
this.textBox1.ScrollToCaret();
}
private void button1_Click(object sender, EventArgs e) {
for (int i = 0; i < 20; i++) {
this.textBox1.AppendText(i + "\r\n");
}
}
When the button1 is pressed it will add the text and when the text is changed the eventHandler is called which will call scrollToCaret().
If you would use this.textBox1.Text += i + "\r\n";
it will not work.
Don't ask me why thats just the way it is - although I think it has something to do with focussing on the control before calling ScrollToCaret(), msdn says the following:
Originally Posted by
msdn
Note This method has no effect if the control does not have focus or if the caret is already positioned in the visible region of the control.
Anyway I hope this solves your problem.
-Ganglylamb.