How can I scroll to a specified line number of a RichTextBox control using C#? It's the WinForms version.
You can try something like this.
void ScrollToLine(int lineNumber)
{
if (lineNumber > richTextBox1.Lines.Count()) return;
richTextBox1.SelectionStart = richTextBox1.Find(richTextBox1.Lines[lineNumber]);
richTextBox1.ScrollToCaret();
}
This will not work perfectly if you have lots of repetition within your RichTextBox. I do hope that it might be of some use to you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With