Changing pictures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcb123 jcb123
    New Member
    • Dec 2011
    • 3

    Changing pictures

    Hi!!

    I have optionboxes on userform1 which dependent on which one is selected, the picture in imagebox1 on userform2 changes. I have got the code working so when i first load the programme and select an option the correct picture comes up. However when i then select a different option the picture doesnt change and remains on the first picture.
    How do I get it to continue to change when different options are selected?
    Hope it makes sense! Thanks in adavance!
    :D
  • BigPapaN0z
    New Member
    • Dec 2011
    • 24

    #2
    I've enclosed a simple example to show. Extract it somewhere and load the project. I've tried to comment on exactly what is happening. If this isn't what you're looking for, please feel free to clarify and I'll help as best as I can!
    Attached Files

    Comment

    • jcb123 jcb123
      New Member
      • Dec 2011
      • 3

      #3
      Hi Thanks for getting back to me!

      However I am unable to open the file you attached. is there anyway of pasting the code directly into the forum.

      Cheers :)

      Comment

      • BigPapaN0z
        New Member
        • Dec 2011
        • 24

        #4
        Sure thing! The project contains 2 forms (frmImage, frmMain). frmImage has a picturebox (picImage) and frmMain has 2 option buttons in an array (optChoices).

        No code in frmImage, copy and paste this in frmMain:

        Code:
        ' Used to preload and hold our images
        Private spicA As StdPicture
        Private spicB As StdPicture
        
        Private Sub Form_Load()
            ' Load the images for use
            Set spicA = LoadPicture(App.Path & "\a.bmp")
            Set spicB = LoadPicture(App.Path & "\b.bmp")
            ' Let's show the Picture form and make it our child
            frmImage.Show vbModeless, Me
        End Sub
        
        Private Sub Form_Unload(Cancel As Integer)
            ' Release/Clear our loaded images
            Set spicB = Nothing
            Set spicA = Nothing
            ' Finally, unload our Picture form
            Unload frmImage
        End Sub
        
        Private Sub optChoices_Click(Index As Integer)
            ' Select case for easy expandability
            Select Case Index
                Case 0      ' A
                    Set frmImage.picImage.Picture = spicA
                Case 1      ' B
                    Set frmImage.picImage.Picture = spicB
            End Select
        End Sub
        As you can see, it looks for a.bmp and b.bmp in the same folder as the program resides. These can be any image (adjust your picturebox on frmImage if you wish).

        I really hope this clarifies things for you, jcb! Feel free to pick my brain some more. :)

        --EDIT--
        By the way, this will NOT load a default image, as no option buttons are selected. If you want to set a default, just add this to your Form_Load:
        Code:
        optChoices(0).Value = True
        Changing the index to something other than 0 will select whichever option button you wish to have selected on load. Also, changing the .Value will also initiate the "Click" event, where we change the images. Just make sure you put the above code AFTER we load the images.(Set spicA = LoadPicure)
        Last edited by BigPapaN0z; Dec 22 '11, 04:43 AM. Reason: Clarification

        Comment

        • jcb123 jcb123
          New Member
          • Dec 2011
          • 3

          #5
          THANK YOU SOOOOOO MUCH!!! :D

          That was a fantastic help! Took me few reads to get it in my head but the code was very similar to what I had already written just with a few tweaks to make it work!

          Much apprieciated! You are a STAR!! :D

          Cheers
          jcb

          Comment

          • BigPapaN0z
            New Member
            • Dec 2011
            • 24

            #6
            Very happy that this was of help, jcb. I've run into the same problem before where you think it should be working but sometimes missing just one or two small points can make a world of difference. :)

            I would ask if this helped you, make sure you choose the post that helped you so other users that search the website with similar problems know the answer that solved your issue.

            Again, if you have any other problems/questions/comments, we're always here to help! Best wishes!

            Comment

            Working...