C# – How to center image in picturebox on resize

cimagepicturebox

How can I center an image in a picturebox as I resize the form? What I have is a picturebox in a panel so if the image is larger than the picturebox, I can get scrollbars on the panel. But this doesn't work with the picturebox size mode "Center Image" and only works with "Auto Size".

Best Answer

This can easily be done with the SizeMode property

pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;