2

我正在 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;
            }
    }
4

1 回答 1

-1

尝试这个:

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      
}
于 2012-09-13T15:27:54.410 回答