求助高手,C#未处理 System.NullReferenceException Message=未将对象引用设置到对象的实例

2025年05月05日 15:06
有1个网友回答
网友(1):

private void button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.HtmlDocument document = this.webBrowser1.Document;
if (document != null)
{
document.All["logname"].SetAttribute("Value", "用户名"); //用户名
document.All["originalLogpasswd"].SetAttribute("Value", "密码"); //密码
document.All["dologin"].RaiseEvent("onClick"); //登录按钮的click事件
document.All["formRegStep1Main"].InvokeMember("submit"); //提交表单
}
}
像你上面那样写 只是return 出去了 if (){} 它还是会执行 if 外面的 若这样写 就不会报错了