|
-
Jun 22nd, 2006, 12:24 AM
#1
Thread Starter
Addicted Member
[2005]How can I get the name of the image in a PictureBox
Hi,
How can I get the name of the image in a PictureBox
I am loading the image into the PictureBox From a resource file
Something like:
VB Code:
dim ImgName as string
ImgName = PictureBox.Image.Name
-
Jun 22nd, 2006, 12:38 AM
#2
Re: [2005]How can I get the name of the image in a PictureBox
The Image doesn't have a name. When you retrieve the Image from the resources you use a named property and that property returns an Image object, but that object has no idea where it came from. If you want to know where it came from then its up to you to store that information somewhere.
There may be a better option for you. Are you using this image in more than one place? If not then there is no specific need to save it explicitly as a resource. If you add an ImageList to your form at run time then you can assign a name to each image. Note that the name is not then a property of the image, but something that the ImageList uses to index the images it contains. You can then retrieve the images by name from the ImageList and the images will still be compiled into the executable.
-
Jun 22nd, 2006, 12:54 AM
#3
Thread Starter
Addicted Member
Re: [2005]How can I get the name of the image in a PictureBox
Hi,
Thank you jmcilhinney, I'll try your suggestion
-
Jun 22nd, 2006, 07:56 AM
#4
Addicted Member
Re: [2005]How can I get the name of the image in a PictureBox
Since you are loading the image, just set the picturebox tag value to the fielname.
VB Code:
PictureBox.tag = "c:\test.jpg"
ImgName = PictureBox.tag
-
Jun 22nd, 2006, 09:03 AM
#5
Re: [2005]How can I get the name of the image in a PictureBox
The Image is coming from an embedded resource. If it was being loaded from a file you wouldn't need to use the Tag property because the .NET 2.0 PictureBox has an ImageLocation property that stores the file path.
-
Jun 22nd, 2006, 09:08 AM
#6
Thread Starter
Addicted Member
Re: [2005]How can I get the name of the image in a PictureBox
Hi,
I find a way, since I am loading the image into the PictureBox From a resource file:
VB Code:
#Region " Declarations "
'Begin Declare Image Array ******************************************
Private MyPicArray As System.Drawing.Image() = {My.Resources.Image01, _
My.Resources.Image02, My.Resources.Image03, My.Resources.Image04, My.Resources.Image05, _
My.Resources.Image06, My.Resources.Image07, My.Resources.Image08, My.Resources.Image09, _
My.Resources.Image10, My.Resources.Image11, My.Resources.Image12}
'End Declare Image Array ******************************************
Dim PicNum As Double
Dim PicName As String
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For PicNum = 0 To MyPicArray.Length - 1
PicName = Format(PicNum, "00") & ".jpg"
MyPicArray(PicNum).Tag = "Image" & PicName
Next
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|