在WebBrowser控件中获取鼠标在网页上点击的位置
2009-07-13 01:21
447 查看
在WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,只有代码了,没有讲解:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
}
void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLElement2 element = document.body as IHTMLElement2;
int scrolltop = webBrowser1.Document.Body.ScrollTop - element.clientTop;
int scrollLeft = webBrowser1.Document.Body.ScrollLeft - element.clientLeft;
if (document.body.parentElement != null)
{
IHTMLElement2 parent = document.body.parentElement as IHTMLElement2;
scrolltop += parent.scrollTop - parent.clientTop;
scrollLeft += parent.scrollLeft - parent.clientLeft;
}
int positionX = e.ClientMousePosition.X + scrollLeft;
int positionY = e.ClientMousePosition.Y + scrolltop;
Debug.WriteLine(string.Format("positionX: {0}, positionY: {1}",
positionX, positionY));
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
}
void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLElement2 element = document.body as IHTMLElement2;
int scrolltop = webBrowser1.Document.Body.ScrollTop - element.clientTop;
int scrollLeft = webBrowser1.Document.Body.ScrollLeft - element.clientLeft;
if (document.body.parentElement != null)
{
IHTMLElement2 parent = document.body.parentElement as IHTMLElement2;
scrolltop += parent.scrollTop - parent.clientTop;
scrollLeft += parent.scrollLeft - parent.clientLeft;
}
int positionX = e.ClientMousePosition.X + scrollLeft;
int positionY = e.ClientMousePosition.Y + scrolltop;
Debug.WriteLine(string.Format("positionX: {0}, positionY: {1}",
positionX, positionY));
相关文章推荐
- 在WebBrowser控件中获取鼠标在网页上点击的位置
- 在WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,
- C++实现WebBrowser控件中对鼠标点击事件的监听,并获取所点击标签的超链接
- MFC 获取picture控件的鼠标点击坐标位置的方法(PreTranslateMessag)
- U6数据导出工具项目总结三 鼠标单击或者双击DataGridView控件时获取鼠标点击位置的值
- 网页效果获取鼠标点击的位置
- MFC 获取picture控件的鼠标点击坐标位置的方法
- MFC 获取picture控件的鼠标点击坐标位置的方法
- MFC 获取picture控件的鼠标点击坐标位置的方法
- JavaScript 获取鼠标点击位置坐标
- js获取鼠标点击的位置-火狐IE兼容
- js获取鼠标点击位置
- CHtmlView 和 Webbrowser 控件中超链接点击事件的获取与检测
- 基于JavaScript实现 获取鼠标点击位置坐标的方法
- JavaScript 获取鼠标点击位置坐标
- MFC/VC中怎样实现slider滑块控件鼠标点击那里,就刚好落到点击位置
- jquery获取点击控件的绝对位置简单实例
- 获取鼠标点击相对于Canva位置的2种方法
- JS 获取鼠标点击位置
- ArcEngine开发——从TocControl上获取鼠标点击位置的信息