![](/img/trans.png)
[英]How to Load an Image onto PictureBox in Visual Studio using C#
[英]How to load image from file into picturebox using C# windows form using Microsoft Visual Studio
我對我的項目有一些問題。 我正在使用 Microsoft Visual Studio 的 C# windows 窗體。
任何人都可以幫助我如何將文件中的圖像加載到圖片框? 我在圖像文件夾上有 300++。
系統可按工號、工號查詢。 或文本框上的名稱。 然后在用戶輸入並單擊文本框上的 Enter 后,圖片框上會出現帶有圖像的員工詳細信息。
所有圖像都是根據他們的作品編號命名的。
信息詳細信息是從數據庫中檢索的,但從文件夾中檢索圖像。 任何人都可以幫助我:)
pictureBox1.Image = Image.FromFile(@"your image file path");
您可以使用OpenFileDialog
來獲取文件路徑
干得好:
PictureBox1.Image = Image.FromFile(@"C:\MyPict.jpg");
為了回應您在評論中發布的代碼,請嘗試一下:
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.