public static Rectangle ToPictureBoxCoordinate(this PictureBox pictureBox, Rectangle imageRectangle) { var upperLeftTransformed = pictureBox.ToPictureBoxCoordinate(imageRectangle.Location); var bottomRightTransformed = pictureBox.ToPictureBoxCoordinate(new Point(imageRectangle.Right, imageRectangle.Bottom)); var transformedRect = new RectangleF(upperLeftTransformed.X, upperLeftTransformed.Y, bottomRightTransformed.X - upperLeftTransformed.X, bottomRightTransformed.Y - upperLeftTransformed.Y); return(Rectangle.Round(transformedRect)); }
public static Rectangle ToPictureBoxCoordinate(this PictureBox pictureBox, Rectangle imageRectangle) { var upperLeftTransformed = pictureBox.ToPictureBoxCoordinate(imageRectangle.Location); var bottomRightTransformed = pictureBox.ToPictureBoxCoordinate(new Point(imageRectangle.Right, imageRectangle.Bottom)); var transformedRect = new RectangleF(upperLeftTransformed.X, upperLeftTransformed.Y, bottomRightTransformed.X - upperLeftTransformed.X, bottomRightTransformed.Y - upperLeftTransformed.Y); return Rectangle.Round(transformedRect); }