WebBrowser.DocumentCompleted WebBrowser.DocumentCompleted WebBrowser.DocumentCompleted WebBrowser.DocumentCompleted Event

定義

發生於 WebBrowser 控制項完成文件的載入時。Occurs when the WebBrowser control finishes loading a document.

public:
 event System::Windows::Forms::WebBrowserDocumentCompletedEventHandler ^ DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler DocumentCompleted;
member this.DocumentCompleted : System.Windows.Forms.WebBrowserDocumentCompletedEventHandler 
Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler 

範例

下列程式碼範例示範如何使用這個事件之後它完全載入後,,列印文件。The following code example demonstrates the use of this event to print a document after it has fully loaded.

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控制項巡覽至新的文件時已設定其中一個下列的屬性或方法呼叫:The WebBrowser control navigates to a new document whenever one of the following properties is set or methods is called:

處理DocumentCompleted事件,以新的文件完成載入時接收通知。Handle the DocumentCompleted event to receive notification when the new document finishes loading. DocumentCompleted事件發生時,完全載入新文件,這表示您可以存取它的內容,透過DocumentDocumentText,或DocumentStream屬性。When the DocumentCompleted event occurs, the new document is fully loaded, which means you can access its contents through the Document, DocumentText, or DocumentStream property.

若要瀏覽開始之前,收到通知,處理Navigating事件。To receive notification before navigation begins, handle the Navigating event. 處理此事件可讓您取消巡覽,如果特定條件未符合,比方說,當使用者未完全填寫表單時。Handling this event lets you cancel navigation if certain conditions have not been met, for example, when the user has not completely filled out a form. 處理Navigated事件,以接收通知時WebBrowser完成導覽控制項,且已開始載入新位置的文件。Handle the Navigated event to receive notification when the WebBrowser control finishes navigation and has begun loading the document at the new location.

如需有關如何處理事件的詳細資訊,請參閱 < 處理和引發事件For more information about handling events, see Handling and Raising Events.

安全性

SecurityPermission
使用此控制項的立即呼叫端。for immediate callers to use this control. 要求值: LinkDemand;[NIB:具名使用權限集合](https://msdn.microsoft.com/library/08250d67-c99d-4ab0-8d2b-b0e12019f6e3): FullTrustDemand value: LinkDemand; [NIB: Named Permission Sets](https://msdn.microsoft.com/library/08250d67-c99d-4ab0-8d2b-b0e12019f6e3): FullTrust.

適用於

另請參閱