实现html文件和c# 交互

首先需要引用程序集: using System.Security.Permissions;

然后将下列代码

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] 

[System.Runtime.InteropServices.ComVisibleAttribute(true)]

放在类和命名空间之间;

在窗体加载写如下代码

           //将同名的html文件放在DEBUG文件夹内
            string str_url = Application.StartupPath + "\\你命名的文件所在debug的路径.html";
            webBrowser.ObjectForScripting = this;
            Uri url = new Uri(str_url);     //设置访问路径
            webBrowser.Url = url;
这样就可以了。

猜你喜欢

转载自blog.csdn.net/buaazx1992/article/details/79522568