|
在开发中,webbrowser控件如何接收鼠标事件,很多事情其实自己动动脑子就有办法的。主要是3步,给dom对象插入js脚本去响应鼠标-〉通过url跳转去通知webbrowser-〉截获跳转事件去c#中处理就可实现了
示例代码:[code=csharp]using System;
using System.Windows.Forms;
using mshtml;
using SHDocVw;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
this.webBrowser1.Navigate("");
SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser;
wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2);
}
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.ToString().ToLower().Trim('/') == "cmd://onmousedown")
{
MessageBox.Show("jinjazz 路过");
e.Cancel = true;
}
}
void wb_NavigateComplete2(object pDisp, ref object URL)
{
mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("document.onmousedown=function(e) { window.location='cmd://onmousedown'}", "javascript");
}
}
}[/code]
|
|