打开PictureBox for PictureBox - C#

时间:2016-11-20 11:09:57

标签: c# picturebox openfiledialog

我不知道这里有什么问题!它打开一个“OpenFileDialog”,它在PictureBox中加载图像,但图像没有拉伸。请帮忙!谢谢:))

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

1 个答案:

答案 0 :(得分:2)

根据需要更改PictureBox的SizeMode-Property。 https://msdn.microsoft.com/de-de/library/system.windows.forms.picturebox.sizemode(v=vs.110).aspx

PictureBox.SizeMode = PictureBoxSizeMode.StretchImage;