Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Visual Basic 2008 Express Edition!
Posted

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]

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...