Windows窗体图片上传错误

时间:2012-02-25 10:47:34

标签: c# winforms visual-studio-2010

我正在编写一个简单的Windows窗体应用程序,我需要让用户设备从PC上传图片,之后我需要在PictureBox控件中显示该图片。 当我浏览图片并按下打开按钮时,它会显示错误对话框,其中包含以下内容: “您的应用程序中发生了未处理的异常。如果单击继续,应用程序将忽略此错误并尝试继续。如果单击退出,应用程序将立即关闭。 该路径不是合法形式“ 这是我的代码:

public partial class Form1 : Form
{
    string Chosen_File = "";

    public Form1()
    {
        InitializeComponent();
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        selectpic.ShowDialog();
        selectpic.Title = "Browse Employee Picture!";
        selectpic.InitialDirectory = "System.Environment.GetFolderPath(Environment.SpecialFolder.Personal)";
        selectpic.FileName = "";
        selectpic.Filter = "JPEG Images|*.jpg|GIF Images|*.gif|BITMAPS|*.bmp";
        Chosen_File = selectpic.FileName;
        pictureBox1.Image = Image.FromFile(Chosen_File);
    }
}

1 个答案:

答案 0 :(得分:1)

另一件事:没有需要报价“

selectpic.InitialDirectory = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);