zerodevice

Hi, i;m building a program that will automatically download images from a specific site.
I am using the C# component (WebBrowser).

however, it requires several steps and pages to be loaded, e.g. differrent catagory and differrent sections.

so, my program has to do:
1. load page A.
2. after page A is loaded, the function "CollectImages" will then search the page for related links.
3. once the search is done, adn added into a listbox, it will then click on to the next page, which is page 2.

ok, so i can do the "download", the "click next page", the "goto navigate", but I CANNOT DO "wait until the page is completely loaded."

do i need a timer do does the WebBrowser component has any methods for this

Please help, me, thanks.


Re: Visual C# Express Edition How to know the page is loaded (100%)

jrboddie

Take a look at the DocumentCompleted event in the WebBrowser control.





Re: Visual C# Express Edition How to know the page is loaded (100%)

zerodevice

hi, thanks.
i saw it.
i'm a little dumb, please provide some samples


i've just tried myself. however, there's something i don't get it.
how do i know detect the page is loaded in my function

the DocumentComplete is an event outside of my function block.




Re: Visual C# Express Edition How to know the page is loaded (100%)

jrboddie

To use the DocumentCompleted event,

1. in the designer, click on the webBrowser control in your form

2. in the properties window, click on the "lightning bolt" icon

3. find the DocumentCompleted event and double click it.

This should take you back to the form code view with a stub for the DocumentCompleted event handler. Now whenever the document has loaded, the code that you put here will be executed.

Here is an example that changes the text of a label showing the status of the document load.

Example: use of DocumentCompleted event in WebBrowser control

private void button1_Click(object sender, EventArgs e)

{

webBrowser1.Navigate(textBox1.Text);

label1.Text = "navigating";

}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

label1.Text = "finished";

}

In your application, you will want the DocumentCompleted code to conditionally trigger additional navigation events depending on the success of the previous downloads.





Re: Visual C# Express Edition How to know the page is loaded (100%)

chacham16

Note that the DocumentCompleted Event is thrown for each FRAME that completes. In order to determine whether or not the whole page has finished loading you must check the ReadyState property of the browser. When it equals READYSTATE_COMPLETE then you know that your page is done.



Re: Visual C# Express Edition How to know the page is loaded (100%)

Papajamboo

Could you please supply an example of this, have tried but the ReadyState is allways set to Complete even if there is more frames that needs to be loaded.