By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,101 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,101 IT Pros & Developers. It's quick & easy.

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

P: 23
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?
Mar 17 '07 #1
Share this Question
Share on Google+
18 Replies


Dököll
Expert 100+
P: 2,364
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
Mar 17 '07 #2

P: 23
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.
Mar 17 '07 #3

devonknows
100+
P: 137
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\MyPic.jpg")

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

Kind Regards
Devon.
Mar 17 '07 #4

P: 23
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\MyPic.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...)

Expand|Select|Wrap|Line Numbers
  1. Private Sub BackToMenu_Click()
  2.  
  3.     Image1 = Nothing
  4.     SingleMenu.Show
  5.  
  6. End Sub
  7. Private Sub Form_Load()
  8.  
  9.     If (SingleMenu.Command1) = True Then
  10.     Image1 = LoadPicture("C:\Frames\f1.gif")
  11.  
  12. ElseIf (SingleMenu.Command2) = True Then
  13.     Image1 = LoadPicture("C:\Frames\f2.gif")
  14.  
  15. ElseIf (SingleMenu.Command3) = True Then
  16.     Image1 = LoadPicture("C:\Frames\f3.gif")
  17.  
  18. ElseIf (SingleMenu.Command4) = True Then
  19.     Image1 = LoadPicture("C:\Frames\f4.gif")
  20.  
  21. ElseIf (SingleMenu.Command5) = True Then
  22.     Image1 = LoadPicture("C:\Frames\f5.gif")
  23.  
  24. ElseIf (SingleMenu.Command6) = True Then
  25.     Image1 = LoadPicture("C:\Frames\f6.gif")
  26. End If
  27.  
  28. 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
Mar 17 '07 #5

Dököll
Expert 100+
P: 2,364
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...
Mar 17 '07 #6

Dököll
Expert 100+
P: 2,364
I should perhaps mention you can also use your code, if you prefer. Still use a background:

Expand|Select|Wrap|Line Numbers
  1.  
  2. If (SingleMenu.Command1) = True Then
  3.     Image1 = LoadPicture("C:\Frames\f1.gif")
  4.  
  5. ElseIf (SingleMenu.Command1) = False Then
  6.     Image1 = LoadPicture("C:\Frames\MyBackground.gif")
  7.  
  8. ElseIf...
  9.  
  10.  
Where you background is again, a blank snapshot...
Mar 17 '07 #7

P: 23
Ok Thanks for your trouble Guys
I'll play with that this evening.
Best regards
Tom
Mar 17 '07 #8

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

Expand|Select|Wrap|Line Numbers
  1.  
  2. If (SingleMenu.Command1) = True Then
  3.     Image1 = LoadPicture("C:\Frames\f1.gif")
  4.  
  5. ElseIf (SingleMenu.Command1) = False Then
  6.     Image1 = LoadPicture("C:\Frames\MyBackground.gif")
  7.  
  8. ElseIf...
  9.  
  10.  
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.microsoft.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...as ending the program clears the memory, is there a way of ending the Imagebox and reinstating it from code?
regards Tom
Mar 17 '07 #9

Dököll
Expert 100+
P: 2,364
Hey Tom!

I will read http://support.microsoft.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!
Mar 17 '07 #10

Dököll
Expert 100+
P: 2,364
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
Mar 17 '07 #11

Dököll
Expert 100+
P: 2,364
You are correct, Tom, regardless our efforts, the code does not seem to work. I wanted to offer a simpler solution:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command1_Click()
  3.     Image1.Visible = True
  4.     Image2.Visible = False
  5.     Image3.Visible = False
  6. End Sub
  7.  
  8. Private Sub Command2_Click()
  9.     Image2.Visible = True
  10.     Image3.Visible = False
  11.     Image1.Visible = False
  12. End Sub
  13.  
  14. Private Sub Command3_Click()
  15.     Image3.Visible = True
  16.     Image2.Visible = False
  17.     Image1.Visible = False
  18. End Sub
  19.  
  20.  
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!
Mar 17 '07 #12

P: 23
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!
Mar 17 '07 #13

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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command1_Click()
  3.     Image1.Visible = True
  4.     Image2.Visible = False
  5.     Image3.Visible = False
  6. End Sub
  7.  
  8. Private Sub Command2_Click()
  9.     Image2.Visible = True
  10.     Image3.Visible = False
  11.     Image1.Visible = False
  12. End Sub
  13.  
  14. Private Sub Command3_Click()
  15.     Image3.Visible = True
  16.     Image2.Visible = False
  17.     Image1.Visible = False
  18. End Sub
  19.  
  20.  
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
Mar 17 '07 #14

Dököll
Expert 100+
P: 2,364
Quite welcome, Tom...
Mar 17 '07 #15

Dököll
Expert 100+
P: 2,364
Greetings Tom!

This should get you going. Slight modification to the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'BG ::Specific to C:\Frames\Background.gif"
  3. 'Image1 ::Specific to Image1 = LoadPicture("C:\Frames\f1.gif") in your code
  4. 'Image2 ::Specific to Image1 = LoadPicture("C:\Frames\f2.gif") in your code
  5. 'Image3 ::Specific to Image1 = LoadPicture("C:\Frames\f3.gif") in your code
  6.  
  7.  
  8. Private Sub Command1_Click()
  9.     BG.Visible = False
  10.     Image1.Visible = True
  11.     Image2.Visible = False
  12.     Image3.Visible = False
  13. End Sub
  14.  
  15. Private Sub Command2_Click()
  16.     BG.Visible = False
  17.     Image1.Visible = False
  18.     Image2.Visible = True
  19.     Image3.Visible = False
  20. End Sub
  21.  
  22.  
  23. Private Sub Command3_Click()
  24.     BG.Visible = False
  25.     Image1.Visible = False
  26.     Image2.Visible = False
  27.     Image3.Visible = True
  28. End Sub
  29.  
  30. 'this is where you would need to revert to blank image as needed (C:\Frames\Background.gif)
  31. Private Sub RefreshMenu_Click()
  32.   Unload Me
  33.   SingleMenu.Show
  34. End Sub
  35.  
  36.  
  37. 'form loads with blank background snapshot set to true for visibility
  38. Private Sub Form_Load()
  39.  
  40. BG.Visible = True 'Specific to C:\Frames\Background.gif"
  41.  
  42. End Sub
  43.  
  44. 'Note: you should change the Image frame  that will be used for background to BG in Name: so it is clear that Image1 = f1.gif, an so on...
  45.  
  46.  
Keep the gif files the way they are. If you want, consider creating images using .bmp extension, better resolution since you have a lot of snapshots to load.

The gif files you now have should not be (re)saved as bmp since the are already in that format, will look about the same, try for next time.

Have fun, Tom, and good luck...

Dököll
Mar 18 '07 #16

P: 23
Greetings Tom!

This should get you going. Slight modification to the code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'BG ::Specific to C:\Frames\Background.gif"
  3. 'Image1 ::Specific to Image1 = LoadPicture("C:\Frames\f1.gif") in your code
  4. 'Image2 ::Specific to Image1 = LoadPicture("C:\Frames\f2.gif") in your code
  5. 'Image3 ::Specific to Image1 = LoadPicture("C:\Frames\f3.gif") in your code
  6.  
  7.  
  8. Private Sub Command1_Click()
  9.     BG.Visible = False
  10.     Image1.Visible = True
  11.     Image2.Visible = False
  12.     Image3.Visible = False
  13. End Sub
  14.  
  15. Private Sub Command2_Click()
  16.     BG.Visible = False
  17.     Image1.Visible = False
  18.     Image2.Visible = True
  19.     Image3.Visible = False
  20. End Sub
  21.  
  22.  
  23. Private Sub Command3_Click()
  24.     BG.Visible = False
  25.     Image1.Visible = False
  26.     Image2.Visible = False
  27.     Image3.Visible = True
  28. End Sub
  29.  
  30. 'this is where you would need to revert to blank image as needed (C:\Frames\Background.gif)
  31. Private Sub RefreshMenu_Click()
  32.   Unload Me
  33.   SingleMenu.Show
  34. End Sub
  35.  
  36.  
  37. 'form loads with blank background snapshot set to true for visibility
  38. Private Sub Form_Load()
  39.  
  40. BG.Visible = True 'Specific to C:\Frames\Background.gif"
  41.  
  42. End Sub
  43.  
  44. 'Note: you should change the Image frame  that will be used for background to BG in Name: so it is clear that Image1 = f1.gif, an so on...
  45.  
  46.  
Keep the gif files the way they are. If you want, consider creating images using .bmp extension, better resolution since you have a lot of snapshots to load.

The gif files you now have should not be (re)saved as bmp since the are already in that format, will look about the same, try for next time.

Have fun, Tom, and good luck...

Dököll

Thankyou for all your hard work Dököll
Best regards
Tom
Mar 18 '07 #17

P: 23
Thankyou for all your hard work Dököll
Best regards
Tom
Hi Dököll!
I'm pleased as punch to report it's working fine! Thanks again.

I put all the code in you suggested and at first it didn't work, then I realised I'd left out the "Unload Me" statement and it burst into life!...

Then I started thinking... I hadn't used that before, so I put it with my original code (below)...and that works too! (my brain hurts now)

I won't forget that line in a hurry!
Thankyou Thankyou

[code]
Private Sub BackToMenu_Click()

Unload Me
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
[code]
Mar 18 '07 #18

Dököll
Expert 100+
P: 2,364
Fantastic, I am glad...Good luck with the project, Tom :-)

In a bit!

Dököll
Mar 18 '07 #19

Post your reply

Sign in to post your reply or Sign up for a free account.