WebBrowser.DocumentCompleted 事件

定义

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

public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler DocumentCompleted;
public event System.Windows.Forms.WebBrowserDocumentCompletedEventHandler? DocumentCompleted;

事件类型

示例

下面的代码示例演示如何使用此事件在文档完全加载后打印文档。

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();
}

注解

WebBrowser每当设置以下属性之一或调用方法时,控件将导航到新文档:

处理 事件以 DocumentCompleted 在新文档完成加载时接收通知。 DocumentCompleted事件发生时,新文档将完全加载,这意味着可以通过 、 DocumentTextDocumentStream 属性访问其内容Document

若要在导航开始前接收通知,请 Navigating 处理 事件。 处理此事件可让你在未满足某些条件(例如,用户尚未完全填写表单时)取消导航。 处理 事件, Navigated 以在 WebBrowser 控件完成导航并开始在新位置加载文档时接收通知。

有关处理事件的详细信息,请参阅 处理和引发事件

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅