Larger Image to fit in picturebox

user676589 picture user676589 · Aug 11, 2011 · Viewed 48.7k times · Source

As you'll can see the first image is the size of (1024*768) and it is correctly displayed in the picturebox and in the second case the image size is (1600*900) and it is displayed to half of the picturebox and the remaining is missing .So No I would like to fir that image in the picturebox no matter what the size is and even though it is greater than the size of the picturebox.I need to scale that Image.So how do I do that?And one more thing is that I need to resize the picturebox automatically when the image loads to it just as we see in the lightbox effect.. http://www.lokeshdhakar.com/projects/lightbox2/ -------->example.

Any help will be appreciated!

Here is what I am getting.

enter image description here

enter image description here

Answer

Fredrik Mörk picture Fredrik Mörk · Aug 11, 2011

If it's a winforms app, you can set the SizeMode property of the PictureBox to PictureBoxSizeMode.Zoom. Note that this will increase the size of smaller images to fill the frame, so you might want to measure the image first, in order to check if either edge is too long, and then setting SizeMode to either PictureBoxSizeMode.Zoom or PictureBoxSizeMode.Normal.