Imports System.IO
Public Class Form1
    Public Overloads Function SearchText(ByVal textToFind As String, Optional ByVal startPosition As Integer = 0, Optional ByVal endPosition As Integer = 0, Optional ByVal highlightText As Boolean = True, Optional ByVal matchCase As Boolean = False) As Integer
        Dim i As Integer
        If endPosition < 1 Then
            If Not matchCase Then
                textToFind = textToFind.ToLower
                Dim temp As String = TextBox1.Text.ToLower
                i = temp.IndexOf(textToFind, startPosition, Me.Text.Length)
            Else
                i = TextBox1.Text.IndexOf(textToFind, startPosition, Me.Text.Length)
            End If
        Else
            If matchCase = False Then
                textToFind = textToFind.ToLower
                Dim temp As String = TextBox1.Text.ToLower
                i = temp.IndexOf(textToFind, startPosition, endPosition)
            Else
                i = TextBox1.Text.IndexOf(textToFind, startPosition, endPosition)
            End If
        End If
        If i > -1 Then
            If highlightText Then
                TextBox1.Focus()
                TextBox1.SelectionStart = i
                TextBox1.SelectionLength = textToFind.Length
            End If
        End If
        Return i
    End Function

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

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim textFound As Integer
        textFound = SearchText(search3.Text, 0, TextBox1.TextLength, True, False)
        TextBox1.ScrollToCaret()
    End Sub
End Class
