public System.Drawing.PointF GetRelativePosition(Control c) { System.Drawing.Point relPoint; System.Drawing.PointF relPointF; relPoint = c.PointToClient(new System.Drawing.Point((int)ScreenX,(int)ScreenY)); relPointF = new System.Drawing.PointF(relPoint.X + ScreenX - (float)((int)ScreenX), relPoint.Y + ScreenY - (float)((int)ScreenY)); return relPointF; }
public static Control FindTopControl(Control parent, Point screen_pt) { Control c = parent.GetChildAtPoint(parent.PointToClient(screen_pt)); if (c == null) { if (parent.RectangleToScreen(new Rectangle(0, 0, parent.Width, parent.Height)).Contains(screen_pt)) return parent; else return null; } else return FindTopControl(c, screen_pt); }
private static Control GetVisibleChildAtDesktopPoint( Control topControl, Point desktopPoint ) { Control foundControl = topControl.GetChildAtPoint( topControl.PointToClient( desktopPoint ) ); if (foundControl != null) { if (foundControl.HasChildren) { foreach (Control control in foundControl.Controls) { foundControl = GetVisibleChildAtDesktopPoint(control, desktopPoint); if (foundControl != null && foundControl.Visible) break; } } } return foundControl ?? topControl; }
// Event attached to System.Windows.Forms.ToolStripItem object. private void tsiMouseEnter(object sender, EventArgs e) { ToolStripItem anItem = (ToolStripItem)sender; _control = anItem.GetCurrentParent(); switch (_location) { case ToolTipLocation.Auto: Rectangle itemRect = new Rectangle(anItem.Bounds.X, 0, anItem.Bounds.Width, _control.Height - 2); show(_control, itemRect); break; case ToolTipLocation.MousePointer: show(_control); break; case ToolTipLocation.CustomClient: show(_control, _customLocation); break; case ToolTipLocation.CustomScreen: Point clientLocation = _control.PointToClient(_customLocation); show(_control, clientLocation); break; } }
public static Color requestColorDialog(Control sender) { Color res = Color.Empty; ContextMenuStrip cm = new ContextMenuStrip(); var ColorDic = new Dictionary<string, Color>(); ColorDic.Add("Red", Color.Red); ColorDic.Add("Blue", Color.Blue); ColorDic.Add("Yellow", Color.Yellow); ColorDic.Add("Green", Color.Green); ColorDic.Add("Transparent", Color.FromArgb(0, 255, 255, 255)); foreach ( KeyValuePair<string, Color> pair in ColorDic) { Bitmap bmp = new Bitmap(10, 10); for(int k = 0; k < bmp.Width; k++) { for(int v = 0; v < bmp.Height; v++) { bmp.SetPixel(k, v, pair.Value); } } cm.Items.Add(new ToolStripMenuItem(pair.Key, bmp, (s, e) => { res = pair.Value; })); } cm.Items.Add(new ToolStripMenuItem("Custom...", new Bitmap(1, 1), (s, e) => { res = oldDialogPicker(); })); cm.Show(sender, sender.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y))); cm.Focus(); while (cm.Visible == true) { Application.DoEvents(); } return res; }
private void Show(System.Windows.Forms.Control control, Rectangle area) { if (control == null) { throw new ArgumentNullException("control"); } Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + Size.Width > (screen.Left + screen.Width)) { location.X = (screen.Left + screen.Width) - Size.Width; } if (location.Y + Size.Height > (screen.Top + screen.Height)) { location.Y -= Size.Height + area.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
public static MouseEventArgs ToEto(this swf.MouseEventArgs e, swf.Control control) { var point = control.PointToClient(swf.Control.MousePosition).ToEto(); var buttons = ToEto(e.Button); var modifiers = swf.Control.ModifierKeys.ToEto(); return(new MouseEventArgs(buttons, modifiers, point, new SizeF(0, (float)e.Delta / WheelDelta))); }
public Input(Control control) { Control = control; _keysDown = new List<Keys>(); _keysPressed = new List<Keys>(); _keysReleased = new List<Keys>(); _mousePoint = control.PointToClient(Cursor.Position); _mouseWheelDelta = 0; }
public static void Scroll(this System.Windows.Forms.Control control) { var pt = control.PointToClient(Cursor.Position); if ((pt.Y + 20) > control.Height) { // scroll down SendMessage(control.Handle, 277, (IntPtr)1, (IntPtr)0); } else if (pt.Y < 20) { // scroll up SendMessage(control.Handle, 277, (IntPtr)0, (IntPtr)0); } }
/// <summary> /// Returns a quaternion for the rotation implied by the window's cursor position /// </summary> public static Quaternion GetRotationFromCursor(System.Windows.Forms.Control control, float fTrackBallRadius) { System.Drawing.Point pt = System.Windows.Forms.Cursor.Position; System.Drawing.Rectangle rc = control.ClientRectangle; pt = control.PointToClient(pt); float xpos = (((2.0f * pt.X) / (rc.Right - rc.Left)) - 1); float ypos = (((2.0f * pt.Y) / (rc.Bottom - rc.Top)) - 1); float sz; if (xpos == 0.0f && ypos == 0.0f) { return(new Quaternion(0.0f, 0.0f, 0.0f, 1.0f)); } float d2 = (float)Math.Sqrt(xpos * xpos + ypos * ypos); if (d2 < fTrackBallRadius * 0.70710678118654752440) // Inside sphere { sz = (float)Math.Sqrt(fTrackBallRadius * fTrackBallRadius - d2 * d2); } else // On hyperbola { sz = (fTrackBallRadius * fTrackBallRadius) / (2.0f * d2); } // Get two points on trackball's sphere Vector3 p1 = new Vector3(xpos, ypos, sz); Vector3 p2 = new Vector3(0.0f, 0.0f, fTrackBallRadius); // Get axis of rotation, which is cross product of p1 and p2 Vector3 axis = Vector3.Cross(p1, p2); // Calculate angle for the rotation about that axis float t = Vector3.Length(Vector3.Subtract(p2, p1)) / (2.0f * fTrackBallRadius); if (t > +1.0f) { t = +1.0f; } if (t < -1.0f) { t = -1.0f; } float fAngle = (float)(2.0f * Math.Asin(t)); // Convert axis to quaternion return(Quaternion.RotationAxis(axis, fAngle)); }
void btnModalityDropDown_Click(object sender, EventArgs e) { System.Windows.Forms.Control parent = GetTopMostControl( ); if (parent == null) { return; } if (!_list.Visible) { Point screenLocation = this.PointToScreen(this.Location); Point controLocation = parent.PointToClient(screenLocation); _list.Left = controLocation.X - this.Left; _list.Top = controLocation.Y + this.Height - this.Top; _list.Width = this.Width - btnModalityDropDown.Width; _list.Font = this.Font; _list.Height = Math.Max(_list.Height, 250); if ((_list.Top + _list.Height) > parent.Height) { _list.Top = controLocation.Y - this.Top - _list.Height; } _list.Visible = true; if (!parent.Controls.Contains(_list)) { parent.Controls.Add(_list); } _list.BringToFront( ); } else { _list.Visible = false; //parent.Controls.Remove ( _list ) ; } }
private bool _IsHovered(Control control, System.Drawing.Point mousePosition) { if (control == null) { return(false); } var mouseToClient = control.PointToClient(mousePosition); var controlForm = GetRootControl(control); if (control.Context || (controlForm != null && controlForm == _ControlAt(mousePosition))) { if (control.Context == false) { for (int i = 0; i < Contexts.Count; i++) { var contextControl = Contexts[i]; if (contextControl == controlForm) { continue; } var contextRect = new System.Drawing.Rectangle(contextControl.Location.X, contextControl.Location.Y, contextControl.Width, contextControl.Height); if (contextRect.Contains(mousePosition)) { return(false); } } } if (control.ClientRectangle.Contains(mouseToClient)) { if (control.mouseEntered == false) { control.mouseEntered = true; control.RaiseOnMouseEnter(new MouseEventArgs(MouseButtons.None, 0, mouseToClient.X, mouseToClient.Y, 0)); HoveredControls.Add(control); } control.hovered = true; control.RaiseOnMouseHover(new MouseEventArgs(MouseButtons.None, 0, mouseToClient.X, mouseToClient.Y, 0)); return(true); } } return(false); }
// Event attached to System.Windows.Forms.Control object. private void ctrlMouseEnter(object sender, EventArgs e) { _control = (System.Windows.Forms.Control)sender; switch (_location) { case ToolTipLocation.Auto: Rectangle ctrlRect = new Rectangle(0, 0, _control.Bounds.Width, _control.Bounds.Height); show(_control, ctrlRect); break; case ToolTipLocation.MousePointer: show(_control); break; case ToolTipLocation.CustomClient: show(_control, _customLocation); break; case ToolTipLocation.CustomScreen: Point clientLocation = _control.PointToClient(_customLocation); show(_control, clientLocation); break; } }
public void Show(Control control, Rectangle area) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); resizableTop = resizableRight = false; Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + Size.Width > (screen.Left + screen.Width)) { resizableRight = true; location.X = (screen.Left + screen.Width) - Size.Width; } if (location.Y + Size.Height > (screen.Top + screen.Height)) { resizableTop = true; location.Y -= Size.Height + area.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
public void ShowForScope(Control control, Point pos) { List<Rectangle> rects = textBox.GetSurroundingRects(scope); Point screenPoint = control.PointToScreen(pos); Point clientPoint = control.PointToClient(screenPoint); Rectangle hitTest = new Rectangle(clientPoint, new Size(4,4)); if(rects.Count>0) { // ShowUnderScopeRect(rects[0], control.PointToScreen(pos), control); foreach (Rectangle rect in rects) { if(rect.IntersectsWith(hitTest)) { ShowUnderScopeRect(rect, control.PointToScreen(pos), control); return; } } base.Show(control, pos); } else { base.Show(control, pos); } }
/// <summary> /// 在父容器中显示显示控件 /// </summary> /// <param name="control">父容器</param> /// <param name="rect">显示区域</param> /// <param name="center">是否居中</param> public void Show(Control control, Rectangle rect, bool center) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); if (_canResize && !_changeRegion) { Padding = new Padding(3); } else if (!_changeRegion) { Padding = new Padding(1); } else { Padding = Padding.Empty; } int width = Padding.Horizontal; int height = Padding.Vertical; base.Size = new Size( _popupControl.Width + width, _popupControl.Height + height); _resizableTop = false; _resizableLeft = false; Point location = control.PointToScreen( new Point(rect.Left, rect.Bottom)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (center) { if (location.X + (rect.Width + Size.Width) / 2 > screen.Right) { location.X = screen.Right - Size.Width; _resizableLeft = true; } else { location.X = location.X - (Size.Width - rect.Width) / 2; } } else { if (location.X + Size.Width > (screen.Left + screen.Width)) { _resizableLeft = true; location.X = (screen.Left + screen.Width) - Size.Width; } } if (location.Y + Size.Height > (screen.Top + screen.Height)) { _resizableTop = true; location.Y -= Size.Height + rect.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
public void Show(Control control, Rectangle area) { if (control == null) { throw new ArgumentNullException("Parent control could not be null"); } SetOwnerItem(control); Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + Size.Width > (screen.Left + screen.Width)) { location.X = (screen.Left + screen.Width) - Size.Width; } if (location.Y + Size.Height > (screen.Top + screen.Height)) { location.Y -= Size.Height + area.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
/// <summary> /// Returns NShapeMouseEventArgs extracted from information provided by the <see cref="T:System.Windows.Forms.Control" /> class. /// </summary> public static MouseEventArgsDg GetMouseEventArgs(Control control, MouseEventType eventType, int clicks, int delta) { Point mousePos = control.PointToClient(Control.MousePosition); return GetMouseEventArgs(eventType, Control.MouseButtons, clicks, mousePos.X, mousePos.Y, delta, control.Bounds); }
private void RaiseMouseEvents(PointF mousePosition, Control control) { var mousePositionInt = new Point((int)mousePosition.X, (int)mousePosition.Y); var mouseRelativePosition = control.PointToClient(mousePositionInt); var controlContainsMousePosition = control.ClientRectangle.Contains(mouseRelativePosition); if (!controlContainsMousePosition && !IsDragging) { control.RaiseOnMouseLeave(EventArgs.Empty); return; } switch (mouseEvent) { case MouseEvents.Down: { var mouseEventArgs = new MouseEventArgs(mouseButton, 1, mouseRelativePosition.X, mouseRelativePosition.Y, 0); control.RaiseOnMouseDown(mouseEventArgs); mouseDownControl = control; return; } case MouseEvents.Up: { if (IsDragging) { if (control.AllowDrop) { var dndData = new DataObject(DraggingData); var dndArgs = new DragEventArgs(dndData, 0, mouseRelativePosition.X, mouseRelativePosition.Y, DragDropEffects.None, dragControlEffects); control.RaiseOnDragDrop(dndArgs); } StopDragDrop(); return; } var mouseEventArgs = new MouseEventArgs(mouseButton, 1, mouseRelativePosition.X, mouseRelativePosition.Y, 0); control.RaiseOnMouseUp(mouseEventArgs); if (mouseDownControl == control) { control.RaiseOnMouseClick(mouseEventArgs); } if (mouseDownControl != null && control != mouseDownControl) { mouseDownControl.RaiseOnMouseUp(mouseEventArgs); } return; } case MouseEvents.DoubleClick: { var mouseEventArgs = new MouseEventArgs(mouseButton, 2, mouseRelativePosition.X, mouseRelativePosition.Y, 0); control.RaiseOnMouseDoubleClick(mouseEventArgs); return; } case MouseEvents.Wheel: { var mouseWheelDeltaCorrected = (int)(-mouseWheelDelta * 4); var mw_args = new MouseEventArgs(MouseButtons.None, 0, mouseRelativePosition.X, mouseRelativePosition.Y, mouseWheelDeltaCorrected); control.RaiseOnMouseWheel(mw_args); updateHoveredControl = true; return; } } }
public static object CallControlPointToClient(Control c, object[] obj) { return(c.PointToClient((System.Drawing.Point)obj[0])); }
public static void RenderControlBgImage(this Control destination, Control source, PaintEventArgs e) { var loc = source.PointToClient((destination.Parent ?? Program.MainWindow).PointToScreen(destination.Location)); if (source.BackgroundImage != null) e.Graphics.DrawImage(source.BackgroundImage, e.ClipRectangle, loc.X + e.ClipRectangle.X, loc.Y + e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height, GraphicsUnit.Pixel); }
/// <summary> /// Set the correct visual state of the target. /// </summary> /// <param name="c">Owning control.</param> protected void UpdateTargetState(Control c) { if ((c == null) || c.IsDisposed) UpdateTargetState(new Point(int.MaxValue, int.MaxValue)); else UpdateTargetState(c.PointToClient(Control.MousePosition)); }
public Point GetRelativePoint(Control parent) { // returns parent if relativeTo doesn't point to an existing control // WoW will not show such controls. // TODO: verify exception handling ISerializableControl baseParent = parent as ISerializableControl; Control relativeControl = baseParent != null ? baseParent.DesignerLoader.BaseControls[this.relativeTo, parent] : null; if (relativeControl == null) relativeControl = parent; FRAMEPOINT relativePoint = this.relativePointSpecified ? this.relativePoint : this.point; Point anchorPoint = Point.Empty; string relativePointText = relativePoint.ToStringValue(); if (relativePointText.StartsWith("BOTTOM")) anchorPoint.Y = relativeControl.Height; if (relativePointText.StartsWith("CENTER")) anchorPoint.Y = relativeControl.Height / 2; if (relativePointText.EndsWith("RIGHT")) anchorPoint.X = relativeControl.Width; if (relativePointText.EndsWith("CENTER")) anchorPoint.X = relativeControl.Width / 2; if (relativeControl != parent) { anchorPoint = relativeControl.PointToScreen(anchorPoint); anchorPoint = parent.PointToClient(anchorPoint); } return anchorPoint; }
/// ------------------------------------------------------------------------------------ /// <summary> /// finds the potential dockhost control at the specified location /// </summary> /// ------------------------------------------------------------------------------------ internal bool FormIsHit(Control c, Point pt) { if (c == null) return false; Point pc = c.PointToClient(pt); bool hit = c.ClientRectangle.IntersectsWith(new Rectangle(pc, new Size(1, 1))); //.TopLevelControl; // this is tricky return hit; }
public static void DragOver(Control owner, DragEventArgs e) { Point p = new Point(e.X, e.Y); Point point2 = owner.PointToClient(p); ImageList_DragMove(point2.X, point2.Y); if (Helper != null) { Helper.DragOver(ref p, (uint) e.Effect); } }
private void ShowUnderScopeRect(Rectangle rect, Point pos,Control control) { Point newPos = new Point(control.PointToClient(pos).X,rect.Y+rect.Height+rect.Height/3); Show(control, newPos); }
/// <summary> /// Source control has lost the focus. /// </summary> /// <param name="c">Reference to the source control instance.</param> public virtual void LostFocus(Control c) { Debug.Assert(c != null); // Validate incoming references if (c == null) throw new ArgumentNullException("c"); // If we are capturing mouse input if (_captured) { // Quit out of any dragging operation if (_dragging) { // Do not release capture! OnDragQuit(); } else { // Release the mouse capture c.Capture = false; _captured = false; } // Recalculate if the mouse is over the button area _mouseOver = _target.ClientRectangle.Contains(c.PointToClient(Control.MousePosition)); } }
/// <summary> /// Key has been released. /// </summary> /// <param name="c">Reference to the source control instance.</param> /// <param name="e">A KeyEventArgs that contains the event data.</param> /// <returns>True if capturing input; otherwise false.</returns> public virtual bool KeyUp(Control c, KeyEventArgs e) { Debug.Assert(c != null); Debug.Assert(e != null); // Validate incoming references if (c == null) throw new ArgumentNullException("c"); if (e == null) throw new ArgumentNullException("e"); // If the user pressed the escape key if (e.KeyCode == Keys.Escape) { // If we are capturing mouse input if (_captured) { // Release the mouse capture c.Capture = false; _captured = false; // End any current dragging operation if (_dragging) OnDragQuit(); // Recalculate if the mouse is over the button area _mouseOver = _target.ClientRectangle.Contains(c.PointToClient(Control.MousePosition)); } } return _captured; }
private void method_1(Control container, Control control, Graphics g, Rectangle bounds) { if (container.ClientRectangle.Width > 0 && container.ClientRectangle.Height > 0 && bounds.Width > 0 && bounds.Height > 0) { var p1 = control.PointToClient(container.PointToScreen(new Point(0, 0))); var p2 = control.PointToClient(container.PointToScreen(new Point(container.ClientRectangle.Right, 0))); using (var brush = new LinearGradientBrush(p1, p2, LayoutBackgroundColor1, LayoutBackgroundColor2)) g.FillRectangle(brush, bounds); } }
//Decode the gesture private void ParseGesture(Control parentControl, ref WinApi.GESTUREINFO gestureInfo) { Location = parentControl.PointToClient(new Point(gestureInfo.ptsLocation.x, gestureInfo.ptsLocation.y)); Center = Location; switch (GestureId) { case WinApi.GID_ROTATE: ushort lastArguments = (ushort)(IsBegin ? 0 : LastEvent.GestureArguments); RotateAngle = WinApi.GID_ROTATE_ANGLE_FROM_ARGUMENT((ushort)(gestureInfo.ullArguments - lastArguments)); break; case WinApi.GID_ZOOM: Point first = IsBegin ? Location : LastBeginEvent.Location; Center = new Point((Location.X + first.X) / 2, (Location.Y + first.Y) / 2); ZoomFactor = IsBegin ? 1 : (double)gestureInfo.ullArguments / LastEvent.GestureArguments; //DistanceBetweenFingers = WinApi.LoDWord(gestureInfo.ullArguments); break; case WinApi.GID_PAN: PanTranslation = IsBegin ? new Size(0, 0) : new Size(Location.X - LastEvent.Location.X, Location.Y - LastEvent.Location.Y); int panVelocity = WinApi.HiDWord((long)(gestureInfo.ullArguments)); PanVelocity = new Size(WinApi.LoWord(panVelocity), WinApi.HiWord(panVelocity)); //DistanceBetweenFingers = WinApi.LoDWord(gestureInfo.ullArguments); break; } }
public void Update() { // Update hovered control. if (hoveredControl != null && dragndrop == false) { var mclient = hoveredControl.PointToClient(Control.MousePosition); var hargs = new MouseEventArgs(MouseButtons.None, 0, mclient.X, mclient.Y, 0); hoveredControl.RaiseOnMouseHover(hargs); if (updateHoveredControl) { hoveredControl.RaiseOnMouseMove(hargs); } } if (updateHoveredControl) { var controlAtMouse = _ControlAt(Control.MousePosition); if (hoveredControl != controlAtMouse && hoveredControl != null) { hoveredControl.hovered = false; hoveredControl.mouseEntered = false; hoveredControl.RaiseOnMouseLeave(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); if (dragndrop) { hoveredControl.RaiseOnDragLeave(EventArgs.Empty); } } if (controlAtMouse == null) { hoveredControl = null; } else { hoveredControl = controlAtMouse; if (controlAtMouse.mouseEntered == false) { var mclient = controlAtMouse.PointToClient(Control.MousePosition); controlAtMouse.hovered = true; controlAtMouse.mouseEntered = true; controlAtMouse.RaiseOnMouseEnter(new MouseEventArgs(MouseButtons.None, 0, mclient.X, mclient.Y, 0)); if (dragndrop) { controlAtMouse.RaiseOnDragEnter(new DragEventArgs(new DataObject(dragData), 0, mclient.X, mclient.Y, DragDropEffects.None, dragControlEffects)); } } } updateHoveredControl = false; } // Update cursor for resize events. if (activeResizeControl == null) { if (hoveredControl == null) { Cursor.CurrentSystem = null; } else { var iResizableControl = hoveredControl as IResizableControl; var resizableControl = iResizableControl as Control; if (iResizableControl != null && resizableControl != null) { var formClientPosition = resizableControl.PointToClient(Control.MousePosition); var hoveredFormResize = iResizableControl.GetResizeAt(formClientPosition); switch (hoveredFormResize) { default: case ControlResizeTypes.None: Cursor.CurrentSystem = null; break; case ControlResizeTypes.Down: case ControlResizeTypes.Up: Cursor.CurrentSystem = Cursors.SizeNS; break; case ControlResizeTypes.Left: case ControlResizeTypes.Right: Cursor.CurrentSystem = Cursors.SizeWE; break; case ControlResizeTypes.LeftDown: case ControlResizeTypes.RightUp: Cursor.CurrentSystem = Cursors.SizeNESW; break; case ControlResizeTypes.LeftUp: case ControlResizeTypes.RightDown: Cursor.CurrentSystem = Cursors.SizeNWSE; break; } } else { Cursor.CurrentSystem = null; } } } var updateEventHandler = UpdateEvent; if (updateEventHandler != null) { updateEventHandler(); } }
/// <summary> /// Source control has lost the focus. /// </summary> /// <param name="c">Reference to the source control instance.</param> public virtual void LostFocus(Control c) { // If we are capturing mouse input if (_captured) { // Release the mouse capture c.Capture = false; _captured = false; // Recalculate if the mouse is over the button area _mouseOver = _target.ClientRectangle.Contains(c.PointToClient(Control.MousePosition)); // Update the visual state UpdateTargetState(c); } }
public void Show(Control control, Rectangle rect, bool center) { if (control == null) { throw new ArgumentNullException("control"); } SetOwnerItem(control); if (_canResize && !_changeRegion) { Padding = new Padding(3); } else if (!_changeRegion) { Padding = new Padding(1); } else { Padding = Padding.Empty; } int width = Padding.Horizontal; int height = Padding.Vertical; base.Size = new Size(_popupControl.Width + width, _popupControl.Height + height); _resizableTop = false; _resizableLeft = false; Point location = control.PointToScreen(new Point(rect.Left, rect.Bottom)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (center) { if (location.X + (rect.Width + Size.Width) / 2 > screen.Right) { location.X = screen.Right - Size.Width; _resizableLeft = true; } else { location.X = location.X - (Size.Width - rect.Width) / 2; } } else { if (location.X + Size.Width > (screen.Left + screen.Width)) { _resizableLeft = true; location.X = (screen.Left + screen.Width) - Size.Width; } } if (location.Y + Size.Height > (screen.Top + screen.Height)) { _resizableTop = true; location.Y -= Size.Height + rect.Height; } location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
private static Control FindControlAt(Control currentControl, Point position) { // Parent bounds. var minX = 0; var minY = 0; var maxX = currentControl.Width; var maxY = currentControl.Height; // Should fix clicking on forms header issue. var currentForm = currentControl as Form; if (currentForm != null) { minY = currentForm.uwfHeaderHeight; } var mouseRelativePosition = currentControl.PointToClient(position); for (int i = currentControl.Controls.Count - 1; i >= 0; i--) { var child = currentControl.Controls[i]; if (!child.Visible || !child.Enabled) { continue; } // Base child bounds. var childOffset = child.uwfOffset; var childX1 = child.Location.X + childOffset.X; var childX2 = childX1 + child.Width; var childY1 = child.Location.Y + childOffset.Y; var childY2 = childY1 + child.Height; if (!child.uwfSystem) { // Skip if out of bounds. if (childX1 > maxX || childY1 > maxY || childX2 < minX || childY2 < minY) { continue; } // Fix. childX1 = Math.Max(minX, childX1); childX2 = Math.Min(maxX, childX2); childY1 = Math.Max(minY, childY1); childY2 = Math.Min(maxY, childY2); if (childX2 < childX1 || childY2 < childY1) { continue; } } var childRect = new Rectangle(childX1, childY1, childX2 - childX1, childY2 - childY1); if (childRect.Contains(mouseRelativePosition)) { currentControl = child; return(FindControlAt(currentControl, position)); } } return(currentControl); }
private void ShowInternal(Control control, Point screenPosition, ToolStripDropDownDirection direction) { this.PerformLayout(); Point show_point = CalculateShowPoint(screenPosition, direction, Size); if (this.Location != show_point) { this.Location = show_point; } // Prevents recursion if (Visible) { return; } SetSourceControl(control); CancelEventArgs e = new CancelEventArgs(); this.OnOpening(e); if (e.Cancel) { return; } // The tracker lets us know when the form is clicked or loses focus ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked); ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange); bool useNativeMenu = true; foreach (var item in this.Items) { useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator; } // Prevent closing native menus by the Application object - it would be too early, in MouseDown. // Native menus will close automatically, *after MouseUp*. This way, we can handle both // ways of selecting the item: mouse_down-move-mouse_up and click-move-click. ToolStripManager.DismissingHandledNatively = useNativeMenu; #if XAMARINMAC if (useNativeMenu) { currentMenu = ToNSMenu(); ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup(); show_point = CalculateShowPoint(screenPosition, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height)); PostMouseUp(control, show_point); NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate { if (control != null) { var winPosition = control.PointToClient(show_point); currentMenu.PopUpMenu(null, new CGPoint(winPosition.X, winPosition.Y), control.Handle.ToNSView()); } else { Size displaySize; XplatUI.GetDisplaySize(out displaySize); currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null); } }); } #endif base.Show(); ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard); // Called from NSMenuDelegate for native menus if (!useNativeMenu) { this.OnOpened(EventArgs.Empty); } }
/// <summary> /// Set the correct visual state of the target. /// </summary> /// <param name="c">Owning control.</param> protected void UpdateTargetState(Control c) { // Check we have a valid control to convert coordinates against if ((c != null) && !c.IsDisposed) { // Ensure control is inside a visible top level form Form f = c.FindForm(); if ((f != null) && f.Visible) { UpdateTargetState(c.PointToClient(Control.MousePosition)); return; } } UpdateTargetState(new Point(int.MaxValue, int.MaxValue)); }
public virtual bool SetCursor(Control frm, uint nHitTest,Point MousePoint) { // trackers should only be in client area frm.PointToClient(MousePoint); if (!frm.ClientRectangle.Contains(MousePoint)) return false; // convert cursor position to client co-ordinates // do hittest and normalize hit int nHandle = (int)HitTestHandles(MousePoint); if (nHandle < 0) return false; // need to normalize the hittest such that we get proper cursors nHandle = NormalizeHit(nHandle); // handle special case of hitting area between handles // (logically the same -- handled as a move -- but different cursor) if (nHandle == (int)TrackerHit.hitMiddle && !m_rect.Contains(MousePoint)) { // only for trackers with hatchedBorder (ie. in-place resizing) if ((m_nStyle & StyleFlags.hatchedBorder)!=0) nHandle = 9; } Debug.Assert(nHandle < 10); frm.Cursor=Cursors[nHandle]; return true; }
internal static Control FindHittestControl(Control parent, int x, int y) { Control child; Point child_point; Point hittest_point; hittest_point = new Point(x, y); child_point = parent.PointToClient(hittest_point); if (parent.ClientRectangle.Contains(child_point)) { return parent; } for (int i=0; i < parent.Controls.Count; i++) { child=parent.Controls[i]; child_point = child.PointToClient(hittest_point); if (child.ClientRectangle.Contains(child_point)) { return child; } if (child.Controls.Count>0) { Control result; result = FindHittestControl(child, x, y); if (result != null) { return result; } } } return null; }
public void TestPublicMethods () { // Public Methods that force Handle creation: // - CreateControl () // - CreateGraphics () // - GetChildAtPoint () // - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created // - PointToClient () // - PointToScreen () // - RectangleToClient () // - RectangleToScreen () Control c = new Control (); c.BringToFront (); Assert.IsFalse (c.IsHandleCreated, "A1"); c.Contains (new Control ()); Assert.IsFalse (c.IsHandleCreated, "A2"); c.CreateControl (); Assert.IsTrue (c.IsHandleCreated, "A3"); c = new Control (); Graphics g = c.CreateGraphics (); g.Dispose (); Assert.IsTrue (c.IsHandleCreated, "A4"); c = new Control (); c.Dispose (); Assert.IsFalse (c.IsHandleCreated, "A5"); c = new Control (); //DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None); //Assert.IsFalse (c.IsHandleCreated, "A6"); //Assert.AreEqual (DragDropEffects.None, d, "A6b"); //Bitmap b = new Bitmap (100, 100); //c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100)); //Assert.IsFalse (c.IsHandleCreated, "A7"); //b.Dispose (); c.FindForm (); Assert.IsFalse (c.IsHandleCreated, "A8"); c.Focus (); Assert.IsFalse (c.IsHandleCreated, "A9"); c.GetChildAtPoint (new Point (10, 10)); Assert.IsTrue (c.IsHandleCreated, "A10"); c.GetContainerControl (); c = new Control (); Assert.IsFalse (c.IsHandleCreated, "A11"); c.GetNextControl (new Control (), true); Assert.IsFalse (c.IsHandleCreated, "A12"); #if NET_2_0 c.GetPreferredSize (Size.Empty); Assert.IsFalse (c.IsHandleCreated, "A13"); #endif c.Hide (); Assert.IsFalse (c.IsHandleCreated, "A14"); c.Invalidate (); Assert.IsFalse (c.IsHandleCreated, "A15"); //c.Invoke (new InvokeDelegate (InvokeMethod)); //Assert.IsFalse (c.IsHandleCreated, "A16"); c.PerformLayout (); Assert.IsFalse (c.IsHandleCreated, "A17"); c.PointToClient (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A18"); c = new Control (); c.PointToScreen (new Point (100, 100)); Assert.IsTrue (c.IsHandleCreated, "A19"); c = new Control (); //c.PreProcessControlMessage ??? //c.PreProcessMessage ??? c.RectangleToClient (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A20"); c = new Control (); c.RectangleToScreen (new Rectangle (0, 0, 100, 100)); Assert.IsTrue (c.IsHandleCreated, "A21"); c = new Control (); c.Refresh (); Assert.IsFalse (c.IsHandleCreated, "A22"); c.ResetBackColor (); Assert.IsFalse (c.IsHandleCreated, "A23"); c.ResetBindings (); Assert.IsFalse (c.IsHandleCreated, "A24"); c.ResetCursor (); Assert.IsFalse (c.IsHandleCreated, "A25"); c.ResetFont (); Assert.IsFalse (c.IsHandleCreated, "A26"); c.ResetForeColor (); Assert.IsFalse (c.IsHandleCreated, "A27"); c.ResetImeMode (); Assert.IsFalse (c.IsHandleCreated, "A28"); c.ResetRightToLeft (); Assert.IsFalse (c.IsHandleCreated, "A29"); c.ResetText (); Assert.IsFalse (c.IsHandleCreated, "A30"); c.SuspendLayout (); Assert.IsFalse (c.IsHandleCreated, "A31"); c.ResumeLayout (); Assert.IsFalse (c.IsHandleCreated, "A32"); #if NET_2_0 c.Scale (new SizeF (1.5f, 1.5f)); Assert.IsFalse (c.IsHandleCreated, "A33"); #endif c.Select (); Assert.IsFalse (c.IsHandleCreated, "A34"); c.SelectNextControl (new Control (), true, true, true, true); Assert.IsFalse (c.IsHandleCreated, "A35"); c.SetBounds (0, 0, 100, 100); Assert.IsFalse (c.IsHandleCreated, "A36"); c.Update (); Assert.IsFalse (c.IsHandleCreated, "A37"); }
public static object CallControlPointToClient(Control c, object[] obj) { return c.PointToClient((Point)obj[0]); }
/// <summary> /// The show. /// </summary> /// <param name="text"> /// The text. /// </param> /// <param name="target"> /// The target. /// </param> /// <param name="arrowLocation"> /// The arrow location. /// </param> /// <exception cref="ArgumentException"> /// </exception> public void Show(string text, Control target, Point arrowLocation) { if (target == null) { throw new ArgumentException("Target control cannot be null"); } var activeScreen = Screen.FromControl(target).WorkingArea; var contentSize = this.GetSize(text); var abLoc = target.PointToScreen(arrowLocation); abLoc.X -= contentSize.Width; abLoc.Y -= contentSize.Height / 2; int diffToScreenBottom = activeScreen.Bottom - (abLoc.Y + contentSize.Height); if (diffToScreenBottom < 0) { abLoc.Y += diffToScreenBottom; } var ttLoc = target.PointToClient(abLoc); this.Show(text, target, ttLoc); }
private Point PointToClientLeftUpperCorner(Control client) { return client.PointToClient(new Point(0, 0)); }
/// <summary> /// Shows pop-up window below the specified area of specified control. /// </summary> /// <param name="control"> /// The control used to compute screen location of specified area. /// </param> /// <param name="area"> /// The area of control below which the pop-up will be shown. /// </param> /// <remarks> /// When there is no space below specified area, the pop-up control is shown above it. /// </remarks> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="control"/> is /// <code> /// null /// </code> /// . /// </exception> public void Show(Control control, Rectangle area) { if (control == null) { throw new ArgumentNullException("control"); } this.SetOwnerItem(control); this.resizableTop = this.resizableRight = false; Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + this.Size.Width > (screen.Left + screen.Width)) { this.resizableRight = true; location.X = (screen.Left + screen.Width) - this.Size.Width; } if (location.Y + this.Size.Height > (screen.Top + screen.Height)) { this.resizableTop = true; location.Y -= this.Size.Height + area.Height; } location = control.PointToClient(location); this.Show(control, location, ToolStripDropDownDirection.BelowRight); }
/// <summary> /// Mouse has entered the view. /// </summary> /// <param name="c">Reference to the source control instance.</param> public virtual void MouseEnter(Control c) { if (!_mouseOver && _menuCheckBox.ItemEnabled) { _mouseReallyOver = _target.ClientRectangle.Contains(c.PointToClient(Control.MousePosition)); _mouseOver = true; ViewManager.SetTarget(this, true); UpdateTarget(); } }
private void Show(Control control, Rectangle area) { if (control == null) throw new ArgumentNullException("control"); Point location = control.PointToScreen(new Point(area.Left, area.Top + area.Height)); Rectangle screen = Screen.FromControl(control).WorkingArea; if (location.X + Size.Width > (screen.Left + screen.Width)) location.X = (screen.Left + screen.Width) - Size.Width; if (location.Y + Size.Height > (screen.Top + screen.Height)) location.Y -= Size.Height + area.Height; location = control.PointToClient(location); Show(control, location, ToolStripDropDownDirection.BelowRight); }
private static bool _ProcessControl(PointF mousePosition, Control control, bool ignore_rect) { // ignore_rect will call mouse_up & mouse_move in any case. var c_location = control.PointToScreen(System.Drawing.Point.Empty); var clientRect = new System.Drawing.RectangleF(c_location.X, c_location.Y, control.Width, control.Height); var contains = clientRect.Contains(mousePosition); if (contains && (mouseEvent == MouseEvents.Down) || mouseEvent == MouseEvents.Up) { if (control.Parent != null) { bool ok = true; var clickedControl = _ParentContains(control, mousePosition, control, ref ok); if (clickedControl != null && ok == false) { control = clickedControl; } } } if (ignore_rect || contains) { var client_mpos = control.PointToClient(new Point((int)mousePosition.X, (int)mousePosition.Y)); if (mousePositionChanged) { if (dragData != null) { dragndrop = true; } } if (!contains && mouseEvent != MouseEvents.Up) { return(true); } switch (mouseEvent) { case MouseEvents.Down: var md_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0); control.RaiseOnMouseDown(md_args); mouseLastClickControl = control; return(true); case MouseEvents.Up: if (dragndrop) { if (control.AllowDrop) { DataObject dnd_data = new DataObject(dragData); DragEventArgs dnd_args = new DragEventArgs(dnd_data, 0, (int)client_mpos.X, (int)client_mpos.Y, DragDropEffects.None, dragControlEffects); control.RaiseOnDragDrop(dnd_args); } dragData = null; dragndrop = false; return(true); } var mu_args = new MouseEventArgs(mouseButton, 1, (int)client_mpos.X, (int)client_mpos.Y, 0); control.RaiseOnMouseUp(mu_args); if (mouseLastClickControl == control) { control.RaiseOnMouseClick(mu_args); } if (mouseLastClickControl != null && control != mouseLastClickControl) { mouseLastClickControl.RaiseOnMouseUp(mu_args); } return(true); case MouseEvents.DoubleClick: var mdc_args = new MouseEventArgs(mouseButton, 2, (int)client_mpos.X, (int)client_mpos.Y, 0); control.RaiseOnMouseDoubleClick(mdc_args); return(true); case MouseEvents.Wheel: var mw_args = new MouseEventArgs(MouseButtons.Middle, 0, (int)client_mpos.X, (int)client_mpos.Y, (int)(-mouseWheelDelta * 4)); control.RaiseOnMouseWheel(mw_args); return(true); } } if (!contains) { control.RaiseOnMouseLeave(null); } return(false); }
private void ShowInternal(Control control, Point screenPosition, ToolStripDropDownDirection direction) { this.PerformLayout(); Point show_point = CalculateShowPoint(screenPosition, direction, Size); if (this.Location != show_point) { this.Location = show_point; } // Prevents recursion if (Visible) { return; } CancelEventArgs e = new CancelEventArgs(); this.OnOpening(e); if (e.Cancel) { return; } // The tracker lets us know when the form is clicked or loses focus ToolStripManager.AppClicked += new EventHandler(ToolStripMenuTracker_AppClicked); ToolStripManager.AppFocusChange += new EventHandler(ToolStripMenuTracker_AppFocusChange); bool useNativeMenu = true; foreach (var item in this.Items) { useNativeMenu &= item is ToolStripMenuItem || item is ToolStripSeparator; } if (useNativeMenu) { currentMenu = ToNSMenu(); ((MonoMenuDelegate)currentMenu.Delegate).BeforePopup(); show_point = CalculateShowPoint(screenPosition, direction, new Size((int)currentMenu.Size.Width, (int)currentMenu.Size.Height)); PostMouseUp(control, show_point); NSApplication.SharedApplication.BeginInvokeOnMainThread(delegate { if (control != null) { var winPosition = control.PointToClient(show_point); currentMenu.PopUpMenu(null, new CGPoint(winPosition.X, winPosition.Y), control.Handle.ToNSView()); } else { Size displaySize; XplatUI.GetDisplaySize(out displaySize); currentMenu.PopUpMenu(null, new CGPoint(show_point.X, displaySize.Height - show_point.Y), null); } }); } base.Show(); ToolStripManager.SetActiveToolStrip(this, ToolStripManager.ActivatedByKeyboard); // Called from NSMenuDelegate for native menus if (!useNativeMenu) { this.OnOpened(EventArgs.Empty); } }