Esempio n. 1
0
        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            // webBrowser1.Document.Encoding = "gb2312";
            // strCache = webBrowser1.DocumentText ;
            tsbSelectElement.Enabled = true;
            //webBrowser1.Document.Click += Document_Click;
            webBrowser1.Document.MouseOver += new HtmlElementEventHandler(Document_MouseOver);
            webBrowser1.Document.MouseMove += new HtmlElementEventHandler(Document_MouseMove);

            //webBrowser1.Document.MouseLeave += new HtmlElementEventHandler(Document_MouseLeave);
            m_hwnd       = webBrowser1.Handle;
            m_hwnd       = WebAPI.GetWindow(m_hwnd, (uint)5); // shell
            m_hwnd       = WebAPI.GetWindow(m_hwnd, (uint)5); // doc obj
            m_hwnd       = WebAPI.GetWindow(m_hwnd, (uint)5); // window
            m_browserPen = new Pen(Color.Red, 2);


            InvokeHelper.Set(rtxtSourceCode, "Text", HtmlCodeFormat.Format(webBrowser1.DocumentText));
        }
Esempio n. 2
0
        void Document_MouseOver(object sender, HtmlElementEventArgs e)
        {
            currentElement = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);
            if (canDrawSelected == true)
            {
                Point p       = WebAutomationHelper.GetOffset(currentElement);
                Point pClient = currentElement.OffsetRectangle.Location;
                int   width   = currentElement.OffsetRectangle.Width;
                int   height  = currentElement.OffsetRectangle.Height;
                // 画框
                Graphics g = Graphics.FromHwnd(m_hwnd);
                // g.DrawRectangle(m_browserPen, m_elemRect);
                elemRect = new Rectangle(pClient.X, pClient.Y, width, height);
                g.DrawRectangle(m_browserPen, p.X, p.Y, width, height);
                g.Dispose();
                rtxtConsoleText.Text += (pClient.X + "," + pClient.Y + "," + width + "," + height) + "\n";
                rtxtConsoleText.Select(rtxtSourceCode.TextLength, 0);
                rtxtConsoleText.ScrollToCaret();
            }



            string      path = "";
            HtmlElement elem = webBrowser1.Document.GetElementFromPoint(e.ClientMousePosition);

            path = WebAutomationHelper.GetElementXPath(elem);
            txtElementXPath.Text = path;
            currentElementXPath  = path;
            InvokeHelper.Set(txtElementXPath, "Text", path);

            System.Threading.Thread.Sleep(200);
            //IHTMLDocument2 document = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            //IHTMLControlElement htmlElem = (IHTMLControlElement)document.onmousemove;
            //txtElementCode.Text = IceFormater.ConvertToXml(elem.OuterHtml, true);
            InvokeHelper.Set(txtElementCode, "Text", HtmlCodeFormat.Format(elem.OuterHtml));
        }