Reputation: 13
I have a listBox where I save paths from Images. We save the paths to sql Database. This works well. My question is, is there a way to click in ListBox
on one of the paths and show the image in a PictureBox
? Would be nice with a mouse click event in ListBox
.
Upvotes: 0
Views: 1591
Reputation: 562
Double click on your ListBox and it should create you a new method.
Paste this code:
string path = listBox1.SelectedItem.ToString();
pictureBox1.Image = Image.FromFile(path);
EDIT:
Like Jimi said in the comments, the above code will lock the file.
Use this code instead:
using (Bitmap tmpBitmap = new Bitmap(listBox1.SelectedItem.ToString()))
{
pictureBox1.Image = new Bitmap(tmpBitmap);
}
Upvotes: 1