c# winform中使用WebKit实现网页与winform的交互

c# winform中使用WebKit实现网页与winform的交互

google下载地址 :https://code.google.com/archive/p/open-webkit-sharp/ 

github网址 : https://github.com/Erls-Corporation/open-webkit-sharp

开发工具:Vs2017

下载之后 解压压缩包. 把Core文件夹和References文件夹下所有文件拷贝到你的工程目录(bin)下,然后打开你的项目,添加引用OpenWebKitSharp.dll和WebKit.Interop.dll(如果你的项目运行在.NET Framework 2.0 或 3.5 引用 Binary_NET2文件夹下的这两个文件,NET4.0的话就引用Binary文件夹下的这两个dll);

到自己的WinForm程序,在工具箱选择按右键-选择项 

点击浏览选择OpenWebKitSharp.dll,然后把WebKitBrowser拖到winfrom窗体里。

想要html页面访问后台   必须在前面加上

//当前类可以com组件的形式供外包调用
//[ComVisible(true)]
//[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]

winfrom后台程序

public class myClass
{
public int Test(int a ,int b)
{
//System.Windows.Forms.MessageBox.Show("alert:JS回调成功");

int c = a * b;
return c;
//System.Windows.Forms.MessageBox.Show("JS回调值alert:"+c);
}

}
private void Form1_Load(object sender, EventArgs e)

webKitBrowser1.Navigate("url");
this.webKitBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webKitBrowser1_DocumentCompleted);

}
public void webKitBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
this.webKitBrowser1.GetScriptManager.ScriptObject = new myClass();

}

原文章地址:https://www.cnblogs.com/wxxf/p/9119315.html

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值