问题
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
.

回答1:
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);
}
来源:https://stackoverflow.com/questions/48785895/c-sharp-open-image-path-from-listbox-and-show-image-in-picturebox