Mr. Smith Mr. Smith - 3 years ago 222
C# Question

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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download