1

只有在 vb.net 网络浏览器中完全加载特定 URL 时,我才能在子例程中运行一些东西。

例如

sub button click

webbrowsernavigate to whatever

(This is what I need)if document has loaded statement
do stuff

end sub

谢谢

4

1 回答 1

1

该类WebBrowser有一个DocumentCompleted可以绑定到的事件:

WebBrowser控件完成加载文档时发生。

MSDN 文章有一个示例,演示了如何有效地使用此事件:

Private Sub PrintHelpPage()

    ' Create a WebBrowser instance.  
    Dim webBrowserForPrinting As New WebBrowser()

    ' Add an event handler that prints the document after it loads. 
    AddHandler webBrowserForPrinting.DocumentCompleted, New _
        WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocument)

    ' Set the Url property to load the document.
    webBrowserForPrinting.Url = New Uri("\\myshare\help.html")

End Sub 

Private Sub PrintDocument(ByVal sender As Object, _
    ByVal e As WebBrowserDocumentCompletedEventArgs)

    Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)

    ' Print the document now that it is fully loaded.
    webBrowserForPrinting.Print()
    MessageBox.Show("print")

    ' Dispose the WebBrowser now that the task is complete. 
    webBrowserForPrinting.Dispose()

End Sub
于 2013-09-05T18:37:14.390 回答