怎么样才可以在WebBrowser的内容中查找指定的字符串并使其高亮显示呢?比如把网页中含有“学习”两字变换为<span style="background-color: #FFFF00">学习</span>
就好象百度中网页快照中的查找关键字高亮显示。

解决方案 »

  1.   

    Dim X As String
    Private Sub Command1_Click()
    With WebBrowser1.Document
    .Open
    .write Replace(X, "学习", "<span style='background-color: #FFFF00'>学习</span>")
    .Close
    End With
    End SubPrivate Sub Form_Load()
    X = "<body>好好学习,天天向上</body>"
    WebBrowser1.Navigate2 ("about:blank")
    Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    With WebBrowser1.Document
    .Open
    .write X
    .Close
    End With
    End Sub
      

  2.   

    northwolves(狼行天下) :
    怎么样对浏览的网页操作呢?能不能在不刷新的情况下进行呢?
      

  3.   

    因为Find方法需要通过IOLECommandTarget接口来实现,通过VB实现很难,下面是VB.NET
    和Delphi的实现方法:HOW TO: Invoke the Find, View Source, and Options Dialog Boxes for the WebBrowser Control from Visual Basic .NEThttp://support.microsoft.com/kb/311288/EN-US/
    How to call the Find dialog in WebBrowser
    http://delphi.about.com/od/adptips2003/a/bltip1103_5.htm
      

  4.   

    http://www.csdn.net/Develop/read_article.asp?id=30263
      

  5.   

    可以在各大搜索引擎搜索微软新闻组的文章
    "convert to VB .Net code - Highlight text using mshtml.IMarkupServices"
      

  6.   

    可以使用pasteHTML来替代处理。
      

  7.   

    个人认为没有很好的办法.重写也存在许多问题.
    如:Private Sub Command1_Click()
    Dim doc, html As Object, strhtml As String
    With WebBrowser1
        If Not .Busy Then
            Set doc = .Document
            Set html = doc.body.createtextrange()
            If Not IsNull(objhtml) Then strhtml = html.htmltext
        End If
            strhtml = Replace(strhtml, "学习", "<span style='background-color: #FFFF00'>学习</span>")
    With .Document
        .OPEN
        .write strhtml
        .Close
    End With
    End With
    End Sub