public static Rectangle Constrain(Rectangle bounds, Rectangle screen) { if (screen.Contains(bounds) || screen.IntersectsWith(bounds)) { return(bounds); } return(RectangleConstraint.Constrain(screen, bounds)); }
public static Rectangle Constrain(Rectangle bounds) { var screen = Screen.FromRectangle(bounds).Bounds; if (screen.Contains(bounds) || screen.IntersectsWith(bounds)) { return(bounds); } return(RectangleConstraint.Constrain(screen, bounds)); }
/// <summary> /// Ensures that the rectangle (location, size) is at least partially visible on screen. /// </summary> public static Point Constrain(Point location, Size size) { var screen = Screen.FromPoint(location).Bounds; var bounds = new Rectangle(location, size); if (screen.Contains(bounds) || screen.IntersectsWith(bounds)) { return(bounds.Location); } return(RectangleConstraint.Constrain(screen, bounds).Location); }