名称" webBrowser"在当前上下文中不存在

时间:2015-09-09 19:53:08

标签: c# .net

我有这段代码:

public void button1_Click(object sender, EventArgs e)
{
    for(int i = 0; i < numericUpDown1.Value; i++)
    {
        WebBrowser webBrowser = new WebBrowser();
        webBrowser.Visible = false;
        webBrowser.ScriptErrorsSuppressed = true;
        webBrowser.Navigate("want to keep it private.");
        webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
    }
}

public void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    HtmlElement botNick = webBrowser.Document.GetElementById("nick");
    botNick.SetAttribute("value", textBox1.Text);

    HtmlElement botPlay = webBrowser.Document.GetElementsByTagName("button")[2];
    botPlay.InvokeMember("click");
}

为什么我得到&#34;名称&#34; webBrowser&#34;在当前上下文中不存在&#34;?

0 个答案:

没有答案