Exemple #1
0
        public static Rectangle Constrain(Rectangle bounds, Rectangle screen)
        {
            if (screen.Contains(bounds) || screen.IntersectsWith(bounds))
            {
                return(bounds);
            }

            return(RectangleConstraint.Constrain(screen, bounds));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        /// <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);
        }