• 在WebBrowser控件中获取鼠标在网页上点击的位置


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

     

  • 相关阅读:
    HNOI2014
    HNOI2018
    HNOI2015
    HNOI2016
    Luogu4099 HEOI2013 SAO 组合、树形DP
    CF915G Coprime Arrays 莫比乌斯反演、差分、前缀和
    CF1110H Modest Substrings AC自动机、DP
    CF1110E Magic Stones 差分
    CentOS 7 配置OpenCL环境(安装NVIDIA cuda sdk、Cmake、Eclipse CDT)
    LeetCode(134) Gas Station
  • 原文地址:https://www.cnblogs.com/killmyday/p/1522198.html
Copyright © 2020-2023  润新知