public static Window syncWithControl(this Window window, System.Windows.Forms.Control control) { if (window.isNull()) { "[API_GuiAutomation] in syncWithControl, provided window value was null".error(); return(null); } Action moveToControl = () => { window.alwaysOnTop(true); var xPos = control.PointToScreen(System.Drawing.Point.Empty).X; var yPos = control.PointToScreen(System.Drawing.Point.Empty).Y; var width = control.width(); var height = control.height(); window.move(xPos, yPos, width, height); }; control.parentForm().Move += (sender, e) => moveToControl(); control.Resize += (sender, e) => moveToControl(); moveToControl(); return(window); }
public static void AbsoluteToScreen(float x, float y, float z, ref int screenX, ref int screenY, Camera camera, System.Windows.Forms.Control form) { float xRatioOver = (x - camera.X) / camera.XEdge; xRatioOver += 1; xRatioOver /= 2.0f; float yRatioOver = (y - camera.Y) / camera.YEdge; yRatioOver -= 1; yRatioOver /= -2.0f; // get the top left // topLeftPoint = new System.Drawing.Point(form.ClientRectangle.Left, form.ClientRectangle.Top); float xPixelOver = xRatioOver * form.ClientRectangle.Width; float yPixelOver = yRatioOver * form.ClientRectangle.Height; System.Drawing.Point point = new System.Drawing.Point((int)xPixelOver, (int)yPixelOver); point = form.PointToScreen(point); screenX = point.X; screenY = point.Y; }
private void SimulateClick(IHTMLElement el) { BrowserWindow bw = browser as BrowserWindow; if (bw != null) { MyBrowser wb = bw.WBBrowser as MyBrowser; Point p = wb.GetScroll(); int scrollTop = p.Y; int scrollLeft = p.X; logger.InfoFormat("scrolltop:{0},scrollleft:{1}", scrollTop, scrollLeft); Rectangle rect = browser.GetAbsolutePosition(el); System.Windows.Forms.Control control = wb as System.Windows.Forms.Control; //获取控件绝对位置 Point location = control.PointToScreen(Point.Empty); Point newPosition = new Point(rect.X + rect.Width / 2 - scrollLeft, rect.Y + location.Y - scrollTop + 2); logger.InfoFormat("new position, x:{0}, y:{0}", newPosition.X, newPosition.Y); AutoRobo.Core.Macro.Macror.LinearSmoothMove(newPosition, 200); MouseSimulator.X = newPosition.X; MouseSimulator.Y = newPosition.Y; MouseSimulator.Click(System.Windows.Forms.MouseButtons.Left); } }
public System.Drawing.Point GetMousePosInControl() { IntPtr ptr = new IntPtr(mWindowHanldle); System.Windows.Forms.Control f = System.Windows.Forms.Control.FromHandle(ptr); System.Drawing.Point p = f.PointToScreen(new System.Drawing.Point(Mouse.MouseState.X.abs, Mouse.MouseState.Y.abs)); System.Drawing.Point cp = System.Windows.Forms.Control.FromHandle(ptr).PointToClient(p); return(cp); }
public static void SetTooltip(this System.Windows.Forms.Control c, string tooltip) { c.MouseMove += (s, e) => { App.ShowToolTip(c.PointToScreen(new Point(e.X + 16, e.Y + 16)), tooltip, null, null, true); }; c.MouseLeave += (s, e) => { App.HideToolTip(); }; }
public static BitmapSource TakeSnapshot(System.Windows.Forms.Control control) { var bounds = control.Bounds; var bitmap = new System.Drawing.Bitmap(bounds.Width, bounds.Height); var screenPoint = control.PointToScreen(new System.Drawing.Point()); System.Drawing.Graphics.FromImage(bitmap).CopyFromScreen( screenPoint, new System.Drawing.Point(), new System.Drawing.Size(bounds.Width, bounds.Height)); return(ConvertBitmap(bitmap)); }
void Control_MouseEnter(object sender, EventArgs e) { System.Windows.Forms.Control control = sender as System.Windows.Forms.Control; if (control != null && this.m_ToolTipInfoDictionary_Control.ContainsKey(control)) { if (!this.m_pToolTipPopup.SetTipInfo(this.m_ToolTipInfoDictionary_Control[control])) { return; } // Point point = control.PointToScreen(new Point(control.DisplayRectangle.Left, control.DisplayRectangle.Bottom)); this.m_pToolTipPopup.Show(new Point(System.Windows.Forms.Form.MousePosition.X + this.OffsetX, point.Y + this.OffsetY)); } }
public static void SetTooltip(this System.Windows.Forms.Control c, TooltipValue tooltip) { c.MouseMove += (s, e) => { var val = tooltip.Value; if (val != null) { App.ShowToolTip(c.PointToScreen(new Point(e.X + 16, e.Y + 16)), val, null, null, true); } }; c.MouseLeave += (s, e) => { App.HideToolTip(); }; }
void SetBufferRect(CarbonWindowInfo carbonWindow) { if (carbonWindow.IsControl == false) { return; } // Todo: See if there is a way around using WinForms. throw new NotImplementedException(); #if false System.Windows.Forms.Control ctrl = Control.FromHandle(carbonWindow.WindowRef); if (ctrl.TopLevelControl == null) { return; } Rect rect = API.GetControlBounds(carbonWindow.WindowRef); System.Windows.Forms.Form frm = (System.Windows.Forms.Form)ctrl.TopLevelControl; System.Drawing.Point loc = frm.PointToClient(ctrl.PointToScreen(System.Drawing.Point.Empty)); rect.X = (short)loc.X; rect.Y = (short)loc.Y; Debug.Print("Setting buffer_rect for control."); Debug.Print("MacOS Coordinate Rect: {0}", rect); rect.Y = (short)(ctrl.TopLevelControl.ClientSize.Height - rect.Y - rect.Height); Debug.Print(" AGL Coordinate Rect: {0}", rect); int[] glrect = new int[4]; glrect[0] = rect.X; glrect[1] = rect.Y; glrect[2] = rect.Width; glrect[3] = rect.Height; Agl.aglSetInteger(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT, glrect); MyAGLReportError("aglSetInteger"); Agl.aglEnable(Handle.Handle, Agl.ParameterNames.AGL_BUFFER_RECT); MyAGLReportError("aglEnable"); #endif }
private System.Drawing.Rectangle GetScreenRect( System.Drawing.Rectangle rect, System.Windows.Forms.Control ctl) { System.Drawing.Rectangle result = System.Drawing.Rectangle.Empty; if (ctl == null) { result = rect; } else { result = GetControlBounds(ctl); if (rect.IsEmpty) { result = GetControlBounds(ctl); } else { result = rect; result.Location = ctl.PointToScreen(result.Location); } } return(result); }