How can I Clear an Image during run time (Newbie)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tomservo
    New Member
    • Mar 2007
    • 23

    How can I Clear an Image during run time (Newbie)

    The Image box is being populated via an If & Then statement, but I need to clear it before the condition changes.
    Are there any 'one-liners' out there?
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Greetings, Tomservo!

    You may be closer than you think. Since you if statement produces the image, why no set visibility to true/false, whereby replacing one image with another.

    Example:

    If this and that Then
    MyPic0.Visible = True
    MyPic1.Visible = False

    ElseIf this and that Then
    MyPic0.Visible = False
    MyPic1.Visible = True

    ElseIf this...
    My...
    My...

    Else

    MsgBox "Darn!"

    End If

    If this does not do it for you, post your if statement so we can have a look.

    Have fun :-)

    Dököll

    Comment

    • Tomservo
      New Member
      • Mar 2007
      • 23

      #3
      Originally posted by Dököll
      Greetings, Tomservo!

      You may be closer than you think. Since you if statement produces the image, why no set visibility to true/false, whereby replacing one image with another.

      Example:

      If this and that Then
      MyPic0.Visible = True
      MyPic1.Visible = False

      ElseIf this and that Then
      MyPic0.Visible = False
      MyPic1.Visible = True

      ElseIf this...
      My...
      My...

      Else

      MsgBox "Darn!"

      End If

      If this does not do it for you, post your if statement so we can have a look.

      Have fun :-)

      Dököll
      Thanks Dököll! I'll get on it now.

      Comment

      • devonknows
        New Member
        • Nov 2006
        • 137

        #4
        Originally posted by Tomservo
        The Image box is being populated via an If & Then statement, but I need to clear it before the condition changes.
        Are there any 'one-liners' out there?
        Also a quick hint, if your actually trying to clear the picture and not just make it non-visible, then use this code,

        Pic1.Picture = Nothing

        That will clear the image box so you can use something like this i guess...

        Pic1.Picture = LoadPicture("C: \MyPictures\MyP ic.jpg")

        Im not to sure which one you meant so i thought i would just give a little hint aswell :D

        Kind Regards
        Devon.

        Comment

        • Tomservo
          New Member
          • Mar 2007
          • 23

          #5
          Originally posted by devonknows
          Also a quick hint, if your actually trying to clear the picture and not just make it non-visible, then use this code,

          Pic1.Picture = Nothing

          That will clear the image box so you can use something like this i guess...

          Pic1.Picture = LoadPicture("C: \MyPictures\MyP ic.jpg")

          Im not to sure which one you meant so i thought i would just give a little hint aswell :D

          Kind Regards
          Devon.
          Thanks Devon,
          That was what I meant, the first suggestion made it invisible but didn't clear it.
          This one clears the image but for some reason it stays clear and won't allow it to be populated again.
          Have a look at the code (I know it's amateurish but I'm getting there...)

          Code:
          Private Sub BackToMenu_Click()
              
              Image1 = Nothing
              SingleMenu.Show
             
          End Sub
          Private Sub Form_Load()
          
              If (SingleMenu.Command1) = True Then
              Image1 = LoadPicture("C:\Frames\f1.gif")
              
          ElseIf (SingleMenu.Command2) = True Then
              Image1 = LoadPicture("C:\Frames\f2.gif")
              
          ElseIf (SingleMenu.Command3) = True Then
              Image1 = LoadPicture("C:\Frames\f3.gif")
              
          ElseIf (SingleMenu.Command4) = True Then
              Image1 = LoadPicture("C:\Frames\f4.gif")
              
          ElseIf (SingleMenu.Command5) = True Then
              Image1 = LoadPicture("C:\Frames\f5.gif")
              
          ElseIf (SingleMenu.Command6) = True Then
              Image1 = LoadPicture("C:\Frames\f6.gif")
          End If
          
          End Sub
          Whats happening is, I can choose any picture from the Menu (command buttons on a previous form) and they load, but then when I go back to the Menu and choose a different one, the original one remains loaded.

          regards
          Tom

          Comment

          • Dököll
            Recognized Expert Top Contributor
            • Nov 2006
            • 2379

            #6
            Good work Devon, thanks for adding your code, Tom...

            Tom use Devon's and my idea to set visibility the way you want, should get you covered. Also you can set up a dummy frame or snapshot the pulls up nothing:

            (1) Use the paint program that comes with Win XP or previous versions
            (2) Create a blank image and use as background, if Nothing background shows

            What this means is, you want to select Pic1 = "Nothing", be sure to also set vivibilty to your background image (dummy image) to True. You should be able to show other snapshots as needed.

            See if that works out...

            Comment

            • Dököll
              Recognized Expert Top Contributor
              • Nov 2006
              • 2379

              #7
              I should perhaps mention you can also use your code, if you prefer. Still use a background:

              Code:
              If (SingleMenu.Command1) = True Then
                  Image1 = LoadPicture("C:\Frames\f1.gif")
                  
              ElseIf (SingleMenu.Command1) = [B]False[/B] Then
                  Image1 = LoadPicture("C:\Frames\MyBackground.gif")
                  
              ElseIf...
              Where you background is again, a blank snapshot...

              Comment

              • Tomservo
                New Member
                • Mar 2007
                • 23

                #8
                Ok Thanks for your trouble Guys
                I'll play with that this evening.
                Best regards
                Tom

                Comment

                • Tomservo
                  New Member
                  • Mar 2007
                  • 23

                  #9
                  Originally posted by Dököll
                  I should perhaps mention you can also use your code, if you prefer. Still use a background:

                  Code:
                  If (SingleMenu.Command1) = True Then
                      Image1 = LoadPicture("C:\Frames\f1.gif")
                      
                  ElseIf (SingleMenu.Command1) = [B]False[/B] Then
                      Image1 = LoadPicture("C:\Frames\MyBackground.gif")
                      
                  ElseIf...
                  Where you background is again, a blank snapshot...

                  Hi Dököll, Me again,
                  No matter what I try of your suggestions it seems to remain either with the same image, or if I use the 'Nothing' parameter, blank.
                  I found this link,

                  http://support.microso ft.com/?id=814675

                  left by someone who has the same problem, the trouble is the solution explained is a bit over my head at the moment...
                  I'd appreciate your view on this if you could give it a look.
                  As an alternative...a s ending the program clears the memory, is there a way of ending the Imagebox and reinstating it from code?
                  regards Tom

                  Comment

                  • Dököll
                    Recognized Expert Top Contributor
                    • Nov 2006
                    • 2379

                    #10
                    Hey Tom!

                    I will read http://support.microso ft.com/?id=814675 momnetarily. Try having the background as the first image to come up, in which case it isn't really an image bu a blank. Sorry for your troubles, wil give it a go with your code, see what the deal is, seems to work with my code.

                    In a bit!

                    Comment

                    • Dököll
                      Recognized Expert Top Contributor
                      • Nov 2006
                      • 2379

                      #11
                      Why is SingleMenu important to your code?

                      Are you hoping when the form loads for the image area to not have an image, thus only adding an image if a Command button is pressed?

                      Dököll

                      Comment

                      • Dököll
                        Recognized Expert Top Contributor
                        • Nov 2006
                        • 2379

                        #12
                        You are correct, Tom, regardless our efforts, the code does not seem to work. I wanted to offer a simpler solution:

                        Code:
                        Private Sub Command1_Click()
                            Image1.Visible = True
                            Image2.Visible = False
                            Image3.Visible = False
                        End Sub
                        
                        Private Sub Command2_Click()
                            Image2.Visible = True
                            Image3.Visible = False
                            Image1.Visible = False
                        End Sub
                        
                        Private Sub Command3_Click()
                            Image3.Visible = True
                            Image2.Visible = False
                            Image1.Visible = False
                        End Sub
                        Assuming you do have the Command buttons mentioned in your code:

                        (1) You would need to layer your Image locations, thus Image1 linked to f1.gif, Image2 linked to f2.gif and so on...

                        (2) The above code would work to make visible each framed image.

                        I will take another look at your code to see what's up...

                        Talk soon!

                        Comment

                        • Tomservo
                          New Member
                          • Mar 2007
                          • 23

                          #13
                          Originally posted by Dököll
                          Why is SingleMenu important to your code?

                          Are you hoping when the form loads for the image area to not have an image, thus only adding an image if a Command button is pressed?

                          Dököll
                          Yes, the program is a Windowframe pricing prog; you choose a style of Windowframe on the form named "SingleMenu " via a command button, and that brings up the calculating form with the correct Windowframe displayed.
                          Having priced one frame, I need it to be possible to price another, possibly different Windowframe, so I programmed a button to take me back to the 'Single section' Windowframe Menu...it's all working fine except for this!

                          Comment

                          • Tomservo
                            New Member
                            • Mar 2007
                            • 23

                            #14
                            Originally posted by Dököll
                            You are correct, Tom, regardless our efforts, the code does not seem to work. I wanted to offer a simpler solution:

                            Code:
                            Private Sub Command1_Click()
                                Image1.Visible = True
                                Image2.Visible = False
                                Image3.Visible = False
                            End Sub
                            
                            Private Sub Command2_Click()
                                Image2.Visible = True
                                Image3.Visible = False
                                Image1.Visible = False
                            End Sub
                            
                            Private Sub Command3_Click()
                                Image3.Visible = True
                                Image2.Visible = False
                                Image1.Visible = False
                            End Sub
                            Assuming you do have the Command buttons mentioned in your code:

                            (1) You would need to layer your Image locations, thus Image1 linked to f1.gif, Image2 linked to f2.gif and so on...

                            (2) The above code would work to make visible each framed image.

                            I will take another look at your code to see what's up...

                            Talk soon!
                            Layering!!... I never thought of that! that could work, I'll give it a go in the morning.
                            Thankyou!
                            regards Tom

                            Comment

                            • Dököll
                              Recognized Expert Top Contributor
                              • Nov 2006
                              • 2379

                              #15
                              Quite welcome, Tom...

                              Comment

                              Working...