Reputation: 49
I have some problem regarding to my project. I'm using C# windows form using Microsoft Visual Studio.
Can anyone help me how to load image from file into picturebox? I have 300++ on image folder.
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.
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 :)
Upvotes: 1
Views: 31235
Reputation: 31
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "Image|*.png;*.jpg;*.bmp;*.gif";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(@openFileDialog.FileName);
}
}
Upvotes: 0
Reputation: 2872
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");
Upvotes: 2
Reputation: 192
pictureBox1.Image = Image.FromFile(@"your image file path");
you can use a OpenFileDialog
to get the file path
Upvotes: 6