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事件发生时,新文档将完全加载,这意味着可以通过 、 DocumentText或 DocumentStream 属性访问其内容Document。
若要在导航开始前接收通知,请 Navigating 处理 事件。 处理此事件可让你在未满足某些条件(例如,用户尚未完全填写表单时)取消导航。 处理 事件, Navigated 以在 WebBrowser 控件完成导航并开始在新位置加载文档时接收通知。
有关处理事件的详细信息,请参阅 处理和引发事件。