highlight text on web page

lshaun

New member
Joined
Jul 17, 2009
Messages
1
Programming Experience
1-3
hi i'm making a web browser as a summer project before i start college and i'm stumped on my find dialog box. any help would be appreciated.


VB.NET:
Public Class Find
    Dim start As Integer = 0
    Dim indexOfSearchText As Integer = 0
    Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click

        Dim strWebPageText As String = Form1.WebBrowser1.Document.Body.InnerText

        Dim startindex As Integer = 0

        If txtFind.Text.Length > 0 Then
            startindex = FindMyText(txtFind.Text.Trim(), start, strWebPageText.Length)
        End If

        ' If string was found in the RichTextBox, highlight it
        If startindex >= 0 Then
            ' Set the highlight color as red
            strWebPageText.SelectionColor = Color.Red
            ' Find the end index. End Index = number of characters in textbox
            Dim endindex As Integer = txtFind.Text.Length
            ' Highlight the search string
            strWebPageText.Select(startindex, endindex)
            ' mark the start position after the position of
            ' last search string
            start = startindex + endindex
        End If
    End Sub
End Class
 
Back
Top