Hi,
You can display a picture on a form (.bmp, .jpg, etc.) using form's .Picture property. But how can I retrieve the filename of that picture file that has been assinged to a form?
Thanks for your help.
Printable View
Hi,
You can display a picture on a form (.bmp, .jpg, etc.) using form's .Picture property. But how can I retrieve the filename of that picture file that has been assinged to a form?
Thanks for your help.
You can't... because it doesn't exist.
When you select the image to be displayed in a picture property it makes a "copy" of the file and loads it internally to be stored within the application.
If the file happened to be a gif or a jpg it also converts it to bmp format losing the transparency (it gets it back by mapping the MaskColor to the base color of the gif transparency however).
The only way to know the filename is to actually use "LoadPicture" within your code to load the image directly and at that time you could use the Tag field to store the name of the file you just loaded.
There is probably a better way to do it, but I've used this method... If using a common dialog control to retrieve and assign a specific picture file to a picture box control, then also save the common dialog "FileName" property to the PictureBox.Tag property. Then simply refer to the Picture box tag property to retrieve the filename whenever you need it. If the picture is something you assign via code, then set the picture box tag property to the same file name at the same time.
Not a perfect solution, but it should work.