ImageGlass.ImageBox.FitRectangle C# (CSharp) Method

FitRectangle() public method

Fits a given T:System.Drawing.Rectangle to match image boundaries
public FitRectangle ( Rectangle rectangle ) : Rectangle
rectangle System.Drawing.Rectangle The rectangle.
return System.Drawing.Rectangle
        public Rectangle FitRectangle(Rectangle rectangle)
        {
            int x;
            int y;
            int w;
            int h;

            x = rectangle.X;
            y = rectangle.Y;
            w = rectangle.Width;
            h = rectangle.Height;

            if (x < 0)
            {
                x = 0;
            }

            if (y < 0)
            {
                y = 0;
            }

            if (x + w > ViewSize.Width)
            {
                w = ViewSize.Width - x;
            }

            if (y + h > ViewSize.Height)
            {
                h = ViewSize.Height - y;
            }

            return new Rectangle(x, y, w, h);
        }

Same methods

ImageBox::FitRectangle ( RectangleF rectangle ) : RectangleF
ImageBox