I want an image within a PictureBox that will adjust automatically depending on the size of the window but, not larger than the original image. While PictureBoxSizeMode.Zoom
almost does this, when the PictureBox is larger than the image it causes the image to pixelate. I'm currently executing this code on resize:
if (pBox.Height * pBox.Height < pBox.Image.Width * pBox.Image.Height) pBox.SizeMode = PictureBoxSizeMode.Zoom;
else pBox.SizeMode = PictureBoxSizeMode.CenterImage;
While this works most of the time, occasionally the image won't revert back to zoom:
Any better way to go about this?
How about setting the maximum size to the image size:
pictureBox1.MaximumSize = pictureBox1.Image.Size;
In Combination with :
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
You should use "if (pBox.Width * pBox.Height < pBox.Image.Width * pBox.Image.Height)" if() Statement. Both dimensions of pBox is taken as height, might cause some problem. Check it
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.