Question

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

Was it helpful?

Solution

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()

OTHER TIPS

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top