Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I scroll to a specified line number of a RichTextBox control using C#?

How can I scroll to a specified line number of a RichTextBox control using C#? It's the WinForms version.

like image 721
Mr. Smith Avatar asked Dec 01 '10 09:12

Mr. Smith


1 Answers

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.

like image 105
jvanrhyn Avatar answered Sep 20 '22 02:09

jvanrhyn