vbMarkO Posted September 10, 2006 Posted September 10, 2006 I have searched all over for this one.... I have foundout how to highlight one word but each instance of a word... rtb1.Find("Line", RichTextBoxFinds.MatchCase) rtb1.SelectionBackColor = Color.Yellow This will find the first instance of the word and Highlight it but how can I get every instance of the word within the rtb1 text and highlight them? I have found 3rd party controls but surely this can be done without them! vbMarkO Quote Visual Basic 2008 Express Edition!
Cags Posted September 10, 2006 Posted September 10, 2006 It might not be the best way, but something like this should work. Dim int As Integer = 0 Dim search As String = "this" While int <> -1 int = RichTextBox1.Text.IndexOf(search, int) If int <> -1 Then RichTextBox1.SelectionStart = int RichTextBox1.SelectionLength = search.Length RichTextBox1.SelectionColor = Color.Yellow int = int + search.Length End If End While [edit]NB. I used SelectionColor not the background one you used as that doesn't appear to be available in .Net 1.1[/edit] Quote Anybody looking for a graduate programmer (Midlands, England)?
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.