1. 首页 > 电脑教程 > C#中winform与webbrower控件交互问题

C#中winform与webbrower控件交互问题

我想实现 js调用 winform里面的方法,通过webbrower控件和winform进行交互。不知道怎么弄啊。我在网上找了些资料,说的在js里面写 window.external.方法名(); 但是没用啊,js报错。。。this.webBrowser1.Url = new Uri(GetDefaultUrl());C# codeusing System;using System.Windows.Forms;using System.Threading;using System.Runtime.InteropServices;namespace WindowsFormsApplication1{[System.Runtime.InteropServices.ComVisibleAttribute(true)] public partial class Form1 : Form{public Form1(){InitializeComponent();webBrowser1.ObjectForScripting = this; }public void Func(string str){MessageBox.Show(str);}private void Form1_Load(object sender, EventArgs e){webBrowser1.Navigate("about:blank");webBrowser1.Document.Write("test");}}}

设置下面两个地方C# code[System.Runtime.InteropServices.ComVisibleAttribute(true)] public partial class Form1 : Form webBrowser1.ObjectForScripting = this;

声明:希维路由器教程网提供的内容,仅供网友学习交流,如有侵权请与我们联系删除,谢谢。ihuangque@qq.com
本文地址:https://www.ctrlcv.com.cn/diannao/169323480910653.html