How can I scroll to a specified line number of a RichTextBox control using C#?
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.
With this code the cursor jumps to the first column in the wanted line.
It works perfectly in any case, even when the wanted line occurs several times.
void GotoLine(int wantedLine_zero_based) // int wantedLine_zero_based = wanted line number; 1st line = 0
{
int index = this.RichTextbox.GetFirstCharIndexFromLine(wantedLine_zero_based);
this.RichTextbox.Select(index, 0);
this.RichTextbox.ScrollToCaret();
}