in general, when the ReadyState property becomes Readystate_complete, the WebBrowser control instructs the Web page to load by triggering the DocumentCompleted event. However, when the loaded Web page contains a frame, the event may be triggered more than once, so it is not easy to judge that the page is loaded.
From the official website of Microsoft, not every frame corresponds to a documentcompleted event, and only the frame that triggered the Downloadbegin event has a corresponding DocumentCompleted event. In addition, the outermost frame is always the last to trigger the DocumentCompleted event. The DocumentCompleted event has an IDispatch * type parameter that indicates the event that is fired on which frame. So, to determine if the document is loaded, just determine if the IDispatch * parameter is the IDispatch of the WebBrowser control.
A description of the issue on the Microsoft Support website:
http://support.microsoft.com/?scid=kb%3Ben-us%3B180366&x=9&y=14
This method uses COM-related knowledge, in the absence of ready-made code, for things like mine. NET began to enter the Windows platform of programmers to understand and implement it has a certain degree of difficulty. In particular, the WebBrowser control under. NET 2.0 is an incomplete encapsulation of webbrowser COM components, and I'm looking at. NET 2.0 IDispatch parameters or related parameters were not found after the WebBrowserDocumentCompletedEventArgs of WebBrowser. It is not known whether it was omitted during the encapsulation process.
I hope that a master can tell me how to implement the above method in C #, thank you first! However, using the outermost frame mentioned above is always the last to trigger the DocumentCompleted event, and there is an easier way to do it:
1. Introduce a counter variable with an initial value of 0;
2. Add one to the counter when the Downloadbegin (navigated in. NET 2.0) event occurs in the WebBrowser control;
3. Subtract one from the counter when the downloadcompleted event of the WebBrowser control occurs;
4. The counter is reduced to 0 to indicate that the document has finished loading
Main code:
// counter
int counter = 0;
// Add an event response function
This . webbrowser.navigated + = new System.Windows.Forms.WebBrowserNavigatedEventHandler (webbrowser_navigated);
this. webbrowser.documentcompleted + = new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler ( This. webbrowser_documentcompleted);
// Event response Function
private void webbrowser_navigated ( object sender, WebBrowserNavigatedEventArgs e)
{
Counter + + ;
}
private void webbrowser_documentcompleted ( object sender, WebBrowserDocumentCompletedEventArgs e)
{
  COUNTER --&NBSP,
if ( 0 == counter)
{
// loading complete
}
}