zoukankan      html  css  js  c++  java
  • 在WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,

    WebBrowser控件中获取鼠标在网页(不是浏览器窗口)上点击的位置,只有代码了,没有讲解:

        首先要引用

    (要引入Microsoft.mshtml.dll 地址是C:\Program Files\Microsoft.NET\Primary Interop Assemblies)

       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));

  • 相关阅读:
    PAT天梯赛练习 L3-004 肿瘤诊断 (30分) 三维BFS
    PAT天梯赛练习 L3-003 社交集群 (30分) DFS搜索
    HDU6375双端队列
    hdu1801 01翻转 贪心
    hdu1677 贪心
    hdu2126 类01背包(三维数组的二维空间优化)
    HLOJ1361 Walking on the Grid II 矩阵快速幂
    HLOJ1366 Candy Box 动态规划(0-1背包改)
    IDEA,与gradle引入jar包报错
    StarUML激活
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/2780363.html
Copyright © 2011-2022 走看看