标签:
---恢复内容开始---
目的:
在动画上面添加点击事件,通过JavaScript调用winfrom方法
1、创建一个页面
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Security.Permissions; using System.Runtime.InteropServices; namespace Demo {
//设置可以调用的范围 [PermissionSet(SecurityAction.Demand, Name = "FullTrust")] [ComVisible(true)] public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { } public void ShowMsg(string msg) { MessageBox.Show(msg); } private void button1_Click(object sender, EventArgs e) { webBrowser2.Document.InvokeScript("Run", new object[] { "CShareFunction" }); } private void webBrowser2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { string flashUri = "D:/text.html"; this.webBrowser2.Url = new Uri(flashUri); webBrowser2.ObjectForScripting = this;//具体公开的对象,这里可以公开自定义对象 } } }
2、html页面
<html> <head> <meta charset="utf-8" /> </head> <body > <img src="BankPay.gif" style="position: absolute; width:100%; top:0px; left:0px; right:0px; bottom:0px; height:100%; z-index:100;" /> <div style="position: absolute; width:100%; top:0px; left:0px; right:0px; bottom:0px; height:100%; z-index:101;" onclick="Run(‘浏览器打开‘)">11111 </div> <script type="text/javascript" charset="utf-8"> function Run(str){ window.external.ShowMsg(str); } </script> </body> </html>
3、注意事项:如果采用flash的话,页面是不能获取到点击事件的
4、flash 的解决方法,通过转换为Gif动画的图片来解决
---恢复内容结束---
标签:
原文地址:http://www.cnblogs.com/cbread/p/4993151.html