WebBrowser.DocumentCompleted 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生於 WebBrowser 控制項完成文件的載入時。
public:
event System::Windows::Forms::WebBrowserDocumentCompletedEventHandler ^ DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler? DocumentCompleted;
member this.DocumentCompleted : System.Windows.Forms.WebBrowserDocumentCompletedEventHandler
Public Custom Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler
Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler
事件類型
範例
下列程式碼範例示範如何使用這個事件,在檔完全載入之後列印檔案。
private void PrintHelpPage()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
// Add an event handler that prints the document after it loads.
webBrowserForPrinting.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(PrintDocument);
// Set the Url property to load the document.
webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");
}
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
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
備註
每當設定下列其中一個屬性或呼叫 方法時,控制項 WebBrowser 就會巡覽至新的檔:
DocumentCompleted處理事件,以在新檔完成載入時接收通知。 DocumentCompleted事件發生時,會完整載入新的檔,這表示您可以透過 Document 、 DocumentText 或 DocumentStream 屬性存取其內容。
若要在導覽開始之前接收通知,請處理 Navigating 事件。 處理此事件可讓您取消流覽,例如,當使用者尚未完整填寫表單時。 Navigated處理事件,以在控制項完成流覽時 WebBrowser 接收通知,並開始在新位置載入檔。
如需處理事件的詳細資訊,請參閱 處理和引發事件。