如何在Gecko Webbrowser c#/。net中使用DocumentComplete Event

时间:2012-08-30 23:47:04

标签: c# .net webbrowser-control gecko readystate

我正在创建一个在c#中包含“geckoWebBrowser”的应用程序。但我必须等待完整加载网页,然后继续执行其他说明。

请帮我处理我的代码:

private void button1_Click(object sender, EventArgs e)
    {
        listBox1.SelectedIndex = 0;
        while (listBox1.Items.Count != 1)
            {
                 geckoWebBrowser1.Navigate(textBox1.Text);

                 // i want to perform below thing after web page load completes

                 listBox1.Items.RemoveAt(listBox1.SelectedIndex);
                 listBox1.SelectedIndex = 0;
                 int i = listBox1.Items.Count;
                 string str = Convert.ToString(i);
                 label2.Text = str;
            }
    }

1 个答案:

答案 0 :(得分:-2)

试试这个:

private void button1_Click(object sender, EventArgs e)
{
    listBox1.SelectedIndex = 0;
    while (listBox1.Items.Count != 1)
        {
             geckoWebBrowser1.DocumentCompleted += new EventHandler(browser_DocumentCompleted);
             geckoWebBrowser1.Navigate(textBox1.Text);
        }
}

void browser_DocumentCompleted(object sender, EventArgs e)
{
    // Do stuff here      
}