TVFavorites Posted April 19, 2004 Posted April 19, 2004 Hi, I�m fairly new at VB.Net and I�m having a few problems highlighting text in a Rich Text Box. I am working on a text editor that will have some text in the RTF Box and a regular text box where the user can enter a search term. When the find button is clicked, the first occurrence of the search term in the RTF box is highlighted if it exists in the Rich TextBox. If find is clicked again, the highlight moves to the next occurrence of the search term and so on. What I have done so far (not sure if this is the best way) is to put the contents of the RTF box into a string variable, search the string with the RTF contents for the find term, highlight the term, and then remove the first occurrence of the search term and everything before it from the string. Problem is, the RTF textbox displayed will need to keep all of the text, so when I search again, the highlighting messes up. Can someone help me with this? Quote
JABE Posted April 20, 2004 Posted April 20, 2004 Use the Find method of the RTF textbox to get the starting index of the search string. Given this starting index (w/c should be greater than -1 if a match is found), use the Select method to highlight the search string. To find subsequent matches, use Find w/ the overloaded version where you can specify the starting index of the search. Finally, don't forget to set HideSelection to False so you can see the highlight effect even if the RTF textbox doesn't have the focus. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.