// The following line works.
imagebox.Image = Image.FromFile("C:/Users/Admin/Desktop/apps/pic1.png");
// The following line does not work.
imagebox.Image = Image.FromFile(imgPath);
// the test Text Box displays "C:/Users/Admin/Desktop/apps/pic1.png", exactly like in the first line
test.Text = imgPath;
当我单击应该更改图片框图像的按钮时,我收到一个错误,基本上说路径中的非法字符,并且ArgumentException 未处理
很抱歉第一次没有这样做。
k 所以实际的文件名被输入到一个文本框中。然后我将该文本转换为字符串,并将其添加到 begging 和 end 以创建完整的文件路径。
string path = "\"C:/Users/Admin/Desktop/apps/";
string ext1 = ".png\"";
ID = idBox.Text;
imgPath = path + ID + ext1;
try
{
imagebox.Image = Image.FromFile(imgPath);
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("Invalid Student or Faculty ID.");
}