[HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
Hi everyone! :)
i have some trouble to finish my program!
my problem is how can i retrieve the name of a picture from a picturebox without extension on a label
SOMETHING LIKE THIS: label1.text = picturebox1.image.text or picturebox1.image.name ( obviously these exemples are wrong i know!)
thank you in advance for your answer!:wave:
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
Picturebox1.ImageLocation seems like what you are looking for.
A list of all Picturebox properties is here:
https://docs.microsoft.com/en-us/dot...5.0#properties
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
In the end, if all you want is the name of the file (no preceding path, and no extension), then you would get the ImageLocation value, and then pass that to Path.GetFileNameWithoutExtension
https://docs.microsoft.com/en-us/dot...n?view=net-5.0
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
Image objects don't have a name. If you expect to get the name of the file that the Image was loaded from then you could have got that when you opened the file. If you want to take OptionBase1's advice and use the ImageLocation property to get the path of the file from which the Image was loaded then you have to have used that property in the first place to load it, or else called the Load method. If you called Image.FromFile and assigned the result to the Image property then the PictureBox has no knowledge of the original file. I suggest that you always do use either ImageLocation or Load to populate a PictureBox from a file, unless you have a specific need for an Image object that you can use elsewhere as well.
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
lol this is why questions should be explicit because I'm thinking he is trying to extract a name from an actual image.
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
Quote:
Originally Posted by
Niya
lol this is why questions should be explicit because I'm thinking he is trying to extract a name from an actual image.
I wasn't really sure myself but the fact that the OP says "without extension" makes me think that it's about the file name. It would be nice if people would actually say what they mean though. Every time we have to assume or guess, there's the chance we'll get it wrong and waste everyone's time.
Re: [HELP CODE BEGINNER] RETRIEVE THE name picture FROM A PICTUREBOX ?
Quote:
Originally Posted by
jmcilhinney
I wasn't really sure myself but the fact that the OP says "without extension" makes me think that it's about the file name. It would be nice if people would actually say what they mean though. Every time we have to assume or guess, there's the chance we'll get it wrong and waste everyone's time.
It was phrased so awkwardly that it didn't even occur to me that he was talking about file extensions. In addition to being explicit, I feel people need to take the time to write their questions. Too many times, like OP in this case, the questions read like they were written and posted in a hurry. On occasions where I ask something I always take my time.
For example, I recently asked this on SO. It took me about 30 minutes to write that because I was constantly re-reading and changing it to make sure I was as clear as possible about what I wanted. And even then I still had to go back and edit it after I posted because someone still misunderstood what I wanted. So yea, man you're right. We can save a lot of time if we are clear on what is being asked.