Importing an image from a file into an image window
In my project, I have a list. When I click on an item in the list, I want a PNG image from a file (stored in 1Global Varible, GV.dir1) in a Picture Box named picBox ... this is what I have ...
picBox.Image = Image.FromFile(GV.dir +
lstFull.SelectedIndex.ToString() + ".png");
GV.dir
equals → @"C:\Files"
+2
source to share
2 answers
You probably need to change this to:
var imageFile = System.IO.Path.Combine(GV.dir, lstFull.SelectedItem.ToString() + ".png");
picBox.Image = Image.FromFile(imageFile);
Note the use of Path.Combine and SelectedItem. The first will take care of skipping the \ characters in your path. The second one will change your text to number (index) to element text.
0
source to share