• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

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

时间:2015年04月02日 15:41:26    来源:魔法猪系统重装大师官网    人气:8702

我想实现 js调用 winform里面的方法,通过webbrower控件和winform进行交互。不知道怎么弄啊。
我在网上找了些资料,说的在js里面写 window.external.方法名();
但是没用啊,js报错。。。

this.webBrowser1.Url = new Uri(GetDefaultUrl());

C# code
using 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;

中,winform,与,webbrower,控件,交互,问题
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部