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

Edited 6 Years Ago by apegram: n/a

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....

This question has already been answered. Start a new discussion instead.