Gecko WebBrowser.ReadyState

5.3k Views Asked by At

I'm creating an application that contains "geckoWebBrowser" in c #. But I have to wait the complete loading a web page, and then continue to execute other instructions. there is something similar to WebBrowser.ReadyState? thank you very much

2

There are 2 best solutions below

0
On

Try this :

private void WaitBrowser(Gecko.GeckoWebBrowser wb)
    {
        while (wb.IsBusy)
        {
            Application.DoEvents();
        }
    }
1
On

Hi GeckoWebBrowser has a DocumentCompleted event you could use it.

Edit:

for example you have a button to show url

private void ShowBtnClick(object sender, EventArgs e)
{
     geckoWebBrowser1.Size = new Size(int.Parse(ViewportWidth.Text), int.Parse(ViewportHeight.Text));

     geckoWebBrowser1.DocumentCompleted += LoadingFinished;

     geckoWebBrowser1.Navigate(PageUrl.Text);
}

private void LoadingFinished(object sender, EventArgs args)
{
    GeckoElement body = geckoWebBrowser1.Document.GetElementsByTagName("body")[0];
    body.SetAttribute("style", "margin-top:-700px");
}