点击picture,弹出文件框,选中文件,更换图片。
//添加图片
private string pathname = string.Empty; //定义路径名变量
private void pictureBoxFood_Click(object sender, EventArgs e)
{
//打开方法
OpenFileDialog file = new OpenFileDialog();
file.InitialDirectory = ".";
file.Filter = "所有文件(*.*)|*.*";
file.ShowDialog();
if (file.FileName != string.Empty)
{
try
{
pathname = file.FileName; //获得文件的绝对路径
this.pictureBoxFood.Load(pathname);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}