To auto scroll of multiline textbox, when add new line or text, the text at the end will be hidden and have to scroll down by the user. Following c# code allows textbox to automatically scroll to the bottom entry when new line is added.
[code]
textBox1.TextChanged += (sender, e) =>
{
textBox1.SelectionStart = textBox1.TextLength;
textBox1.ScrollToCaret();
textBox1.Refresh(); //If textBox1 works to scroll down without this line then preferably avoid this line to improve performance
};
[/code]
The line handles TextChanged event of the textbox, whenever the text is changed, textbox will be scrolled down to bottom. Please make sure that Multiline property of the TextBox is set to True.
On internet, I found people saying TextBox's AppendText() method do auto scrolling but didn't work for me.
This is also valid for RichTextBox.
Posted Article in Programming