首页  编辑  

更改页面中的文字

Tags: /C#/界面处理/WebBrowser/   Date Created:

//

using mshtml ;

private void Form1_Load( object sender , EventArgs e)

{

   webBrowser1 . Navigate( "http://www.baidu.com" );

}

private void webBrowser1_DocumentCompleted( object sender , WebBrowserDocumentCompletedEventArgs e)

{

    IHTMLDocument2 vDocument = ( IHTMLDocument2 )webBrowser1 . Document . DomDocument;

    IHTMLBodyElement vBody = ( IHTMLBodyElement )vDocument . body;

    IHTMLTxtRange vTxtRange = ( IHTMLTxtRange )vBody . createTextRange();

    if (vTxtRange . findText( " , int . MaxValue, 0 ))

   {

       vTxtRange . select();

       vTxtRange . pasteHTML(

            @"<a href=""http://blog.sina.com.cn/zswang"" " +

            @"target=""_blank""><b>Zswang</b> );

   }

}

//---------------

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

   WebBrowser1.Navigate( "http://www.baidu.com" )

End Sub

Private Sub WebBrowser1_DocumentCompleted( ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

    Dim vDocument As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument

    Dim vBody As mshtml.IHTMLBodyElement = vDocument.body

    Dim vTxtRange As mshtml.IHTMLTxtRange = vBody.createTextRange

    If vTxtRange.findText( " ) Then

       vTxtRange.select()

       vTxtRange.pasteHTML( "<a href=""http://blog.sina.com.cn/zswang"" target=""_blank""><b>Zswang</b> )

    End If

End Sub