//两个按钮,用来操作一个webbrowser控件。 private void button1_Click(object sender, EventArgs e)
{ webBrowser1.Navigate("http://www.xxx.org.cn/XXYY.aspx");
//其中一个按钮用来调用网页
} private void button2_Click(object sender, EventArgs e)
{ webbrowser1.Document.GetElementById("value", "myname");
webbrowser1.pswd1.SetAttribute("value", "12345678");
webbrowser1.pswd2.SetAttribute("value", "12345678");
webbrowser1.btnSubmit.InvokeMember("click");
//另一个按钮用来人工控制输入账号和密码信息
} private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{ HtmlElement myname = webBrowser1.Document.GetElementById("XINGMING");
HtmlElement pswd1 = webBrowser1.Document.All["txtPSWD"];
HtmlElement pswd2 = webBrowser1.Document.All["txtTKWD"];
HtmlElement btnSubmit = webBrowser1.Document.All["btnView"];
//webbrowser的输入账号和密码的部分
}//问题是,如果把button2的代码移到webbrowser中的末尾,能够正常运行,而在button2中,就报告“当前上下文中不存在名称webbrowser1”,请问如何解决?多谢了,新手分不多。
{ webBrowser1.Navigate("http://www.xxx.org.cn/XXYY.aspx");
//其中一个按钮用来调用网页
} private void button2_Click(object sender, EventArgs e)
{ webbrowser1.Document.GetElementById("value", "myname");
webbrowser1.pswd1.SetAttribute("value", "12345678");
webbrowser1.pswd2.SetAttribute("value", "12345678");
webbrowser1.btnSubmit.InvokeMember("click");
//另一个按钮用来人工控制输入账号和密码信息
} private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{ HtmlElement myname = webBrowser1.Document.GetElementById("XINGMING");
HtmlElement pswd1 = webBrowser1.Document.All["txtPSWD"];
HtmlElement pswd2 = webBrowser1.Document.All["txtTKWD"];
HtmlElement btnSubmit = webBrowser1.Document.All["btnView"];
//webbrowser的输入账号和密码的部分
}//问题是,如果把button2的代码移到webbrowser中的末尾,能够正常运行,而在button2中,就报告“当前上下文中不存在名称webbrowser1”,请问如何解决?多谢了,新手分不多。
错误1 “System.Windows.Forms.WebBrowser”不包含“tbUserid”的定义,并且找不到可接受类型为“System.Windows.Forms.WebBrowser”的第一个参数的扩展方法“tbUserid”(是否缺少 using 指令或程序集引用?)是不是某些变量要设成公用的等等,怎么弄呀
不过引用pswd1、pswd2和btnSubmit的格式肯定不对,因为把这两部分的代码合并以后就不报错,但是仍然无法显示正常的窗体。