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
Printable View
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
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.
Hi,
Thank you jmcilhinney, I'll try your suggestion
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
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.
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