VB.NET - Search And Highlight Text In A RichTextBox

VB.NET - How To Search And Highlight Text In A RichTextBox Using Visual Basic.NET


In This VB.NET Tutorial We Will See How To Search And Highlight Text In A RichTextBox 
Using Visual Basic .NET Programming Language .


Project Source Code:

Public Class VBNET_Text_Search


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim startText As Integer = 0
        Dim endText As Integer

        endText = RichTextBox1.Text.LastIndexOf(TextBox1.Text)

        RichTextBox1.SelectAll()
        RichTextBox1.SelectionBackColor = Color.White


        While startText < endText

            RichTextBox1.Find(TextBox1.Text, startText, RichTextBox1.TextLength, RichTextBoxFinds.MatchCase)
            RichTextBox1.SelectionBackColor = Color.Brown

            startText = RichTextBox1.Text.IndexOf(TextBox1.Text, startText) + 1


        End While

    End Sub
End Class


///////////////OUTPUT:

vb.net search text and highlight




Share this

Related Posts

Previous
Next Post »

2 comments

comments