Can i get Image path from PictureBox?

albertkhor

Well-known member
Joined
Jan 12, 2006
Messages
150
Programming Experience
Beginner
i have a database which is use to store a photo and i use PictureBox to show the photo. Can i get Image path from PictureBox?
 
In .Net 2.0 the PictureBox got an ImageLocation property you can get/set, also when using Load method, but not when just assigning an image/bitmap to the Image property.

For .Net 1.1 you have to manage this yourself, one tip is to also put the path in the Tag property of the control.

Please update your Primary Platform in User CP, albertkhor.
 
Can I get image path from picture box?

Hi albertkhor. I am not sure if this is exactly what you want, but at least it will give you something to work on that I know works because I have just built it for you and am copying and pasting the code.
Start a new project. On the Form put a PictureBox and two buttons. Also from the Toolbox you will need to double-click on an OpenFileDialog. I changed the Name of mine to ofdLookalike.
To the first button click event, put this code:-
VB.NET:
[COLOR=seagreen]'Show the open file dialog box.[/COLOR]
If ofdLookalike.ShowDialog = DialogResult.OK Then
[COLOR=green]'Load picture into picture box.[/COLOR]
picPictureShow.Image = Image.FromFile(ofdLookalike.FileName)
[COLOR=green]'Show the name of the file in the Form's caption[/COLOR].
Me.Text = "Picture Show (" & ofdLookalike.FileName & ")"
End If
Now, put this code in to the second button's click event:-
VB.NET:
MsgBox("Picture Show (" & ofdLookalike.FileName & ")")
If I can help you further I shall do my utmost to do so.
VB.NET:
Sometimes, just having the tools is not enough - a good guide will show how to use them.
:cool: :D
 
TwoWing, you could very well be right that albertkhor didn't mean what he was asking: if it is possible to read the file path of the image the picturebox is currently displaying.. :)
 
I have just tested my proj again. With the first button click the OFD gets the user to locate a picture in its 'file' and put it in the PictureBox. The second click the OFD tells the user how it found it.(To put it simply!)
Build it and see for yourself.
In any case, albertkhor will have something he can exercise with. I learned a lot from having a simple thing like that.
 
Back
Top