I am blocked in using the WebBrowser document for MouseDown
event Handler.
Designer:
this.webBrowser.TabIndex = 4;
this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(this.WebBrowser_DocumentCompleted);
Form class:
private void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser.Document.MouseDown += new HtmlElementEventHandler(webBrowser_MouseDown);
}
private void webBrowser_MouseDown(object sender, HtmlElementEventArgs e)
{
}
In the code above, when loading the first URL selected, it will call DocumentCompleted
.
According to documentation, the WebBrowser's document should be complete when this event is raised.
But I meet an error because webBrowser.Document
is null and I didn't find any explanation.
Is there a way to retrieve the loaded Document in DocumentCompleted
?