Rahul
Rahul

Reputation: 2234

How Do I scroll to a string in a Rich Text Box

I ahve a RTB with sufficent text that scrolling is needed
user enters a string and I highlight all occurrences using a combination of Find and Select which is great but now I want the ability for a user to press Next and the next higlighted instance should be visible say 2at /3rd of the bounding rectangle ( I would even settle for at the top of the bound.

How do I scroll to an index basically ( I am caching the indices as I find and markup )

oh also this is C# Winforms .NET 2.0

Upvotes: 2

Views: 5885

Answers (2)

Durgpal Singh
Durgpal Singh

Reputation: 11953

private void myrichTextBox_TextChanged(object sender, EventArgs e)
{
   myrichTextBox.SelectionStart = myrichTextBox.Text.Length; //Set the current caret position             at the end
   myrichTextBox.ScrollToCaret(); //Now scroll it automatically
}

Upvotes: 1

xpda
xpda

Reputation: 15813

Set the selection start to the next location, and then use ScrollToCaret to scroll to that location in the rich text box.

rText1.SelectionStart = i
rText1.ScrollToCaret()

Upvotes: 4

Related Questions