本文主要简单的记录winform如何与html文件中的信息如何进行交互,即在winform中加载html界面,从而可以进行相互调用。

1.新建一个winform项目,若要在winform中加载html,需要一个webBrowser控件。

2.新建一个html页面,这里命名为“test.htm”.

3.c#代码:

//为了使网页能够与winform交互 将com的可访问性设置为真
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)] public void Hello()
{
MessageBox.Show("OK,html在调用wf中的函数");
} private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.ObjectForScripting = this;
string path = Application.StartupPath + @"\test.htm";
//MessageBox.Show(path);
//this.webBrowser1.Navigate(path);
this.webBrowser1.Url = new System.Uri(path, System.UriKind.Absolute);
}

4.html代码:

<html>
<head>
<title>this is a test</title>
<script type ="text/javascript">
function Hello() {
window.external.Hello();//getDebugPath()为c#方法
//alert("hello");
}
</script>
</head>
<body>
<button id="btn" onclick="Hello()">hello</button>
</body>
</html>

5.结果:这里算是简单的完成了在winform中加载html,并在js中调用了c#中的信息。

6.为了方便,直接在上面的基础上实现在winform中调用html中的js函数。关键点:this.webBrowser1.Document.InvokeScript("js 的函数名", 参数");

7.c#代码:直接拖动一个button控件到页面中。

private void button1_Click(object sender, EventArgs e)
{
this.webBrowser1.Document.InvokeScript("WfToHtml");
}

8.js代码:

<script type ="text/javascript">
function WfToHtml() {
alert("wf调用html里面的js函数");
}
</script>

9.结果:

初学者,内容也比较简单,准备再加载一个swf,哈哈。。。

winform 与 html 交互 简单案例的更多相关文章

  1. winform 通过 html 与swf 交互 简单案例

    在上一篇 winform 与 html 交互 简单案例 中讲了winform与html之间的简单交互,接下来的内容是在winform中以html为中转站,实现将swf嵌入winform中并实现交互. ...

  2. Ajax与ashx异步请求的简单案例

    Ajax与ashx异步请求的简单案例: 前台页面(aspx): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  3. WPF+MVVM学习总结 DataGrid简单案例

    一.WPF概要 WPF(Windows Presentation Foundation)是微软推出的基于Windows 的用户界面框架,属于.NET Framework 3.0的一部分.它提供了统一的 ...

  4. WebView JS交互 JSBridge 案例 原理 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  5. asp.net——Ajax与ashx异步请求的简单案例

    Ajax与ashx异步请求的简单案例: 前台页面(aspx): <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

  6. java基础之Socket编程概述以及简单案例

    概述: 用来实现网络互连的 不同的计算机上 运行的程序间 可以进行数据交互  也就是用来在不同的电脑间, 进行数据传输. 三大要素: IP地址: 设备(电脑,手机,ipad)在网络中的唯一标识. 组成 ...

  7. Servlet请求头response应用简单案例

    Servlet请求头response应用简单案例:访问AServlet重定向到BServlet,5秒后跳到CServlet,并显示图片: AServlet package cn.yzu; import ...

  8. [Design Pattern] Front Controller Pattern 简单案例

    Front Controller Pattern, 即前端控制器模式,用于集中化用户请求,使得所有请求都经过同一个前端控制器处理,处理内容有身份验证.权限验证.记录和追踪请求等,处理后再交由分发器把请 ...

  9. [Design Pattern] Observer Pattern 简单案例

    Observer Pattern,即观察者模式,当存在一对多关系,例如一个对象一有变动,就要自动通知被依赖的全部对象得场景,属于行为类的设计模式. 下面是一个观察者模式的简单案例. Observer ...

随机推荐

  1. How to Display Image In Picturebox in VC++ from Iplimage and Mat

    Introduction This tip/trick will be useful to OpenCV programmers, who wish to use Windows Form appli ...

  2. FatMouse' Trade

    /* problem: FatMouse' Trade this is greedy problem. firstly:we should calculate the average J[i]/F[i ...

  3. apache vhost 访问权限配置

    apache的<directory>     </directory>语句,查考如下: 如何访问根目录下的目录http://192.168.1.12/test/ 第一.缺省ap ...

  4. Krypton Factor

    Krypton Factor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. B. Mr. Kitayuta's Colorful Graph

     B. Mr. Kitayuta's Colorful Graph  time limit per test 1 second Mr. Kitayuta has just bought an undi ...

  6. Android(java)学习笔记108:通过反射获取私有构造方法并且使用

    反射获取私有构造方法并且使用: 1.获取字节码文件.class对象:          Class c = Class.forName("cn.itcast_01.Person") ...

  7. FineUploader 学习笔记

    FineUploader既是开源的又是收费的,这个没搞懂. 先看效果:

  8. 故事板 — 视图切换(segue)与传值

    1.传值问题:为什么不能给控件的接口赋值 如执行Segue跳转 [self performSegueWithIdentifier:GAPlayeVideo sender:gaVideo]; //在跳转 ...

  9. [Yii2]Access to debugger is denied due to IP address restriction. The requesting IP address is

    在更新到正式平台,看到runtime/app.log 有 Access to debugger is denied due to IP address restriction. The request ...

  10. ubuntu共享文件夹给virtualbox

    在ubuntu或者linuxmint等linux系统下安装了virtualbox,可以通过共享文件夹的方式,把文件夹共享给virtualbox下的虚拟机系统,我这里的虚拟机系统是win7,共享过程如下 ...