C# TextBox Scroll to Cursor

To scroll a C# TextBox to the cursor/caret, it’s important that the TextBox is both visible and focused, then call the ScrollToCaret method:
textBox.Focus();
textBox.ScrollToCaret();
To scroll to the bottom/end of a TextBox, set the SelectionLength to 0 to remove any selection, then set SelectionStart to the end of the text in the TextBox:
textBox.SelectionLength = 0;
textBox.SelectionStart = textBox.Text.Length;
textBox.Focus();
textBox.ScrollToCaret();
Previous
Next Post »