winforms - c# Check if any picture applied -
i'm trying show image folder user selected.and if slected record not have picture, show image called
empty.png
here's code wrote. how can change it fit wrote in explaination?(the top of question)
string[] fileentries = directory.getfiles(@"c:\projects_2012\project_noam\files\proteinpic"); foreach (string filename in fileentries) { if (filename.contains(combobox1.selecteditem.tostring())) { image image = image.fromfile(filename); // set picturebox image property image. // ... then, adjust height , width properties. picturebox1.image = image; picturebox1.height = image.height; picturebox1.width = image.width; } }
i don't think need iterate through every file in directory acheive want
image image; string imagepath = system.io.path.combine(@"c:\projects_2012\project_noam\files\proteinpic", combobox1.selecteditem.tostring()); if (system.io.file.exists(imagepath)) { image = image.fromfile(imagepath); } else { image = image.fromfile(@"c:\projects_2012\project_noam\files\proteinpic\empty.png"); } picturebox1.image = image; picturebox1.height = image.height; picturebox1.width = image.width;
Comments
Post a Comment