blah blah blah is here! blah blah » Close

up0down
link

I have a number of Pictureboxes with images(png) in an app. How do I get the full path and filename of the image that is in the Picturebox through the click event. The images may be in the project bin or Resources section.

Thanks

last answered 2 years ago

1 answers

up0down
link

Well, if you always use the Load(url) method to load the image into the PictureBox, then the file path will be stored in the PictureBox's ImageLocation property.

However, if you're setting the PictureBox's Image property directly from some pre-loaded image, then there's no obvious way to get back to the file path.

I think in the latter situation, each time you load an image into the application, I'd add the image's 'friendly' name (as the key) and its full file path (as the value) to a Dictionary. Then, every time you reset the PictureBox's Image property, I'd set a private string field to the image's friendly name. You'll then be able to easily get the currently displayed image's file path from the Dictionary.

Feedback