Results 1 to 6 of 6

Thread: [2005]How can I get the name of the image in a PictureBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    [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:
    1. dim ImgName as string
    2.  
    3. ImgName = PictureBox.Image.Name

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: [2005]How can I get the name of the image in a PictureBox

    Hi,

    Thank you jmcilhinney, I'll try your suggestion

  4. #4
    Addicted Member
    Join Date
    Mar 2006
    Posts
    235

    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:
    1. PictureBox.tag = "c:\test.jpg"
    2.  
    3. ImgName = PictureBox.tag

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    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:
    1. #Region " Declarations "
    2.     'Begin Declare Image Array ******************************************
    3.     Private MyPicArray As System.Drawing.Image() = {My.Resources.Image01, _
    4.        My.Resources.Image02, My.Resources.Image03, My.Resources.Image04, My.Resources.Image05, _
    5.        My.Resources.Image06, My.Resources.Image07, My.Resources.Image08, My.Resources.Image09, _
    6.        My.Resources.Image10, My.Resources.Image11, My.Resources.Image12}
    7.     'End Declare Image Array ******************************************
    8.     Dim PicNum As Double
    9.     Dim PicName As String
    10. #End Region
    11.  
    12.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.         For PicNum = 0 To MyPicArray.Length - 1
    14.             PicName = Format(PicNum, "00") & ".jpg"
    15.             MyPicArray(PicNum).Tag = "Image" & PicName
    16.         Next
    17.     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
  •  



Click Here to Expand Forum to Full Width