/// <summary> /// 获取某一个元素的屏幕位置 /// </summary> /// <param name="browser"></param> /// <param name="element"></param> /// <returns></returns> static public Rectangle GeScreenPosition(this Browser browser, IHTMLElement element) { Rectangle rect = GetAbsolutePosition(browser, element); IHTMLElement frame = GetFrame(element); Rectangle frameRect; while (frame != null) { frameRect = GetAbsolutePosition(browser, frame); rect.Offset(frameRect.X, frameRect.Y); frame = GetFrame(frame); } //frame = GetFrame(frame); //if (frame != null) //{ // frameRect = GetAbsolutePosition(browser, frame); // rect.Offset(frameRect.X, frameRect.Y); //} int width = element.offsetWidth; int height = element.offsetHeight; MyBrowser my = browser.GetMyBrowser(); rect.Offset(my.PointToScreen(Point.Empty)); return(rect); }
// Calculate image and screen coordinates of the point private void GetImageAndScreenPoints(Point point, out Point imgPoint, out Point screenPoint) { Rectangle rc = myBrowser.ClientRectangle; int width = (int)(this.width * zoom); int height = (int)(this.height * zoom); Point scrollPosition = myBrowser.GetScroll(); int x = (rc.Width < width) ? scrollPosition.X : (rc.Width - width) / 2; int y = (rc.Height < height) ? scrollPosition.Y : (rc.Height - height) / 2; int ix = Math.Min(Math.Max(x, point.X), x + width - 1); int iy = Math.Min(Math.Max(y, point.Y), y + height - 1); ix = (int)((ix - x) / zoom); iy = (int)((iy - y) / zoom); // image point imgPoint = new Point(ix, iy); // screen point screenPoint = myBrowser.PointToScreen(new Point((int)(ix * zoom + x), (int)(iy * zoom + y))); }