【发布时间】:2025-09-23 21:30:03
【问题描述】:
// 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.");
}
【问题讨论】:
-
你得到什么错误信息?
-
请不要在标题前加上“C#”。这就是我们在 SO 上使用标签的目的。
-
错误信息?例外?无声的失败?
标签: c# string image picturebox fromfile