C# winform使用webBrowser记录

C# winform使用webBrowser记录

 1 //使网页能够与winform交互 将com的可访问性设置为真
 2     [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
 3     [System.Runtime.InteropServices.ComVisible(true)]
 4 
 5  private void Form1_Load(object sender, EventArgs e)
 6         {
 7             //webBrowser1.Navigate(new Uri("https://www.cnblogs.com/cmt/p/13966899.html"));
 8             webBrowser1.ScriptErrorsSuppressed = true;
 9             webBrowser1.ObjectForScripting = this;
10             webBrowser1.Navigate(Application.StartupPath + @"	est.html");
11 
12             //webBrowser1.Document.InvokeScript("js 的函数名", 参数");
13             /*(1)调用html的JS函数
14             webBrowser.Document.InvokeScript(“DoAdd”, new object []{ “这个是我要传给前台的值1”,”这个是我要传给前台的值2”});
15             注意:DoAdd就是 html的funcation名称
16             (2)获取html值
17             webBrowser.All[“txtName”].GetAttribute(“value”);
18             (3)给html控件赋值
19             webBrowser.All[“txtName”].SetAttribute(“value”, “这个是我要赋给他们的值”);
20             (4)调用html控件的按钮事件
21             webBrowser.All[“txtName”].InvokeMember(“onclick”);
22             (5)注册html按钮事件,使它的事件,调用后台事件(建议在webBrowser_DocumentCompleted事件中注册)
23             webBrowser.All[“txtName”].Click += new HtmlElementEventHandler(html_btnClouse_Click);
24             void html_btnClouse_Click(object sender, HtmlElementEventArgs e)
25             {
26             this.Close();
27             }
28             */
29         }
30         public void Hello()
31         {
32             MessageBox.Show("html调用wf函数成功!");
33         }
原文地址:https://www.cnblogs.com/Lxk0825/p/15456928.html