Click to See Complete Forum and Search --> : Search and display text in richtextbox


clatten
September 20th, 2004, 09:26 AM
I want to do a simple search function in a richtextbox. I have loaded a file and by using the Find method it's possible to find a text string, highlight the string and extract the line number, but how can I programatically scroll down to the line?

private int findText(string searchText, int searchStart, int searchEnd)
{
int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase);
richTextBox1.SelectionColor = Color.Blue;
int lineNo= richTextBox1.GetLineFromCharIndex(indexToText);
return indexToText;
}

clatten
September 20th, 2004, 11:13 AM
Shuld have figured it out earlier, ScrollToCaret do actually work IF the control has focus.


richTextBox1.Focus();
richTextBox1.ScrollToCaret();