Return name of image in a picturebox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MattGaff
    New Member
    • Oct 2007
    • 24

    Return name of image in a picturebox

    I have a list of images in the resource file of a VB project and a particular picture box on my form gets populated with an image depending on certain conditions:
    Code:
    picNotify.Image = My.Resources.[ImageName]
    Later on in my program I want to query the name of the image in the picturebox. Technically I could create a variable and pass the name of the image in the same piece of code above but I dont like creating unnecessary variables if I am able to extract the information via code.

    Is this possible?
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    You can use sender in the Click_Event.

    I didn't test it but it should be something like this:
    Code:
    Private Sub picPicturebox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picPicturebox.Click
      Dim picTempPicturebox As Picturebox = sender
      Msgbox(sender.Name)
    End Sub
    Steven

    Comment

    • MattGaff
      New Member
      • Oct 2007
      • 24

      #3
      Sorry that does not work. The name of my picture box is called picNotify and that part of your code returns "picNotify" .
      I need the name of the image contained in the picture box

      Thanks for trying though, appreciate it.

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        How about sender.Image then?

        Steven

        Comment

        • MattGaff
          New Member
          • Oct 2007
          • 24

          #5
          Afraid not.
          The code you gave me isnt necessary because I can access all the same options by just calling the name of the picture box. I cannot find the actual name of the picture being used anywhere at all in the code.

          Have a go yourself......s tart a blank project (windows form), add a picture box, assign it any picture at all and then see if you can find the name of the picture from run-time.

          Also as a help, if you do :
          Code:
           msgbox (picBox)
          where picBox is the name of your picture box control, then it will go to debugging mode. You can highlight the picture box to show all list of properties and I still can't find the name. Its driving me a bit mad!!

          Comment

          Working...