DannyDSB DannyDSB - 17 days ago 5
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

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;