DannyDSB DannyDSB - 1 year ago 150
C# Question

Open Image for PictureBox - C#

I don't know what's wrong here! It opens up a "OpenFileDialog", it loads up the image in the PictureBox but the image isn't streched. Please help! Thanks :)

private void browsePic_Click(object sender, EventArgs e)
openPicture.Filter = "PNG|*.png|JPG|*.jpg;*.jpeg";
if(openPicture.ShowDialog() == DialogResult.OK)
pictureBox2.BackgroundImageLayout = ImageLayout.Stretch;
pictureBox2.Image = new Bitmap(openPicture.FileName);

Answer Source

Change the SizeMode-Property of the PictureBox as you need. https://msdn.microsoft.com/de-de/library/system.windows.forms.picturebox.sizemode(v=vs.110).aspx

PictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download