Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching in labels
#3
I agree here is how to do it in a richtext box if you do decide to go ahead and do so

add 1 textbox
add 1 Button
add 1 Richtextbox

Code

Code:
Public Class Form1
    Sub findTextAndHighlight(ByVal searchtext As String, ByVal rtb As RichTextBox)
        Dim textEnd As Integer = rtb.TextLength
        Dim index As Integer = 0
        Dim fnt As Font = New Font(rtb.Font, FontStyle.Bold)
        Dim lastIndex As Integer = rtb.Text.LastIndexOf(searchtext)
        While (index < lastIndex)
            rtb.Find(searchtext, index, textEnd,
            RichTextBoxFinds.WholeWord)
            rtb.SelectionFont = fnt
            rtb.SelectionLength = searchtext.Length
            rtb.SelectionColor = Color.Black
            rtb.SelectionBackColor = Color.Yellow
            index = rtb.Text.IndexOf(searchtext, index) + 1
        End While
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        findTextAndHighlight(TextBox1.Text, RichTextBox1)
    End Sub
End Class

I could not find a way either hope this helps in some way

Kind Regards

Bradley


Messages In This Thread
Searching in labels - by brco900033 - 05-25-2012, 09:51 AM
Re: Searching in labels - by Bradley - 05-25-2012, 11:47 PM
Re: Searching in labels - by brco900033 - 06-06-2012, 08:10 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)