DannyDSB
DannyDSB

Reputation: 145

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);
        }
    }

Upvotes: 0

Views: 1524

Answers (1)

NikxDa
NikxDa

Reputation: 4187

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;

Upvotes: 2

Related Questions