使用C#加载图像

时间:2016-02-06 12:45:33

标签: c# image load

我  打开图像我尝试了这种方法但是当我点击按钮时窗口不会出现 所以我无法加载图像

    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();
        if (open.ShowDialog() == DialogResult.OK)
        {

            pictureBox1.ImageLocation = open.FileName;   

        }

2 个答案:

答案 0 :(得分:0)

这样做可以完美地显示完整的图像。

 private void button1_Click_1(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();
        if (open.ShowDialog() == DialogResult.OK)
        {

            pictureBox1.ImageLocation = open.FileName;
            pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

        }
    }

答案 1 :(得分:-1)

有" Open"和"取消" OpenfileDialog上的按钮。因为没有" OK"按钮,"如果条件"不会是真的。你应该把它改成:

Private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog open = new OpenFileDialog();
        if (open.ShowDialog() != DialogResult.Cancel)
        {

            pictureBox1.ImageLocation = open.FileName;   

        }
    }