简体   繁体   English

如何使用 Microsoft Visual Studio 使用 C# windows 窗体将文件中的图像加载到图片框

[英]How to load image from file into picturebox using C# windows form using Microsoft Visual Studio

I have some problem regarding to my project.我对我的项目有一些问题。 I'm using C# windows form using Microsoft Visual Studio.我正在使用 Microsoft Visual Studio 的 C# windows 窗体。

Can anyone help me how to load image from file into picturebox?任何人都可以帮助我如何将文件中的图像加载到图片框? I have 300++ on image folder.我在图像文件夹上有 300++。

The system can search by work no., empl no.系统可按工号、工号查询。 or name on text box.或文本框上的名称。 Then after user typing and click enter on the textbox, the employee details with image appears on the picture box.然后在用户输入并单击文本框上的 Enter 后,图片框上会出现带有图像的员工详细信息。

All the image is name according to their work no.所有图像都是根据他们的作品编号命名的。

The information details is retrieve from database but image from folder.信息详细信息是从数据库中检索的,但从文件夹中检索图像。 Can anyone help me please :)任何人都可以帮助我:)

pictureBox1.Image = Image.FromFile(@"your image file path");

您可以使用OpenFileDialog来获取文件路径

Here you go:干得好:

PictureBox1.Image = Image.FromFile(@"C:\MyPict.jpg");

In response to your code posted in the comment, give this a try:为了回应您在评论中发布的代码,请尝试一下:

const string imageFolderPath = @"C:\photo\";

var imageName = textBoxWorkNo.Text;
var fullImagePath = imageFolderPath + imageName + ".jpg";

if (File.Exists(fullImagePath))
    pictureBox1.Image = Image.FromFile(fullImagePath);
else MessageBox.Show("File not exist");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM