RichTextBox1.SelectionStart = RichTextBox1.Find("Not Found")
        RichTextBox1.SelectionColor = Color.Red

that is my code.. my problem is in my richtextbox1, there are many line that contain "Not Found". So how can i change colour for all of that text to red colour? my code only work only with a single line that contain "Not Found".

Create a loop. It should execute as long as it finds instances of your search text. With each iteration, it starts the next search after the previous starting location. When the text is not found, .Find(...) returns -1, and the loop will exit.

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

        Dim startingPoint As Integer = -1
        Do
            startingPoint = RichTextBox1.Find("Not Found", startingPoint + 1, RichTextBoxFinds.None)
            If (startingPoint >= 0) Then
                RichTextBox1.SelectionStart = startingPoint
                RichTextBox1.SelectionLength = "Not Found".Length
                RichTextBox1.SelectionColor = Color.Red
            End If
        Loop Until startingPoint < 0

    End Sub

Create a loop. It should execute as long as it finds instances of your search text. With each iteration, it starts the next search after the previous starting location. When the text is not found, .Find(...) returns -1, and the loop will exit.

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

        Dim startingPoint As Integer = -1
        Do
            startingPoint = RichTextBox1.Find("Not Found", startingPoint + 1, RichTextBoxFinds.None)
            If (startingPoint >= 0) Then
                RichTextBox1.SelectionStart = startingPoint
                RichTextBox1.SelectionLength = "Not Found".Length
                RichTextBox1.SelectionColor = Color.Red
            End If
        Loop Until startingPoint < 0

    End Sub

Its works..... Thanks alot....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.