Search and display text in richtextbox
-
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; }
-
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; }
Why not just use the
ScrollToCaret()
method ofRichTextBox
? ;) Regards, mav -
Why not just use the
ScrollToCaret()
method ofRichTextBox
? ;) Regards, mav