473,405 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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?
Mar 17 '07 #1
18 1251
Dököll
2,364 Expert 2GB
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
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
137 100+
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
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
2,364 Expert 2GB
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
2,364 Expert 2GB
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
Ok Thanks for your trouble Guys
I'll play with that this evening.
Best regards
Tom
Mar 17 '07 #8
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
2,364 Expert 2GB
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
2,364 Expert 2GB
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
2,364 Expert 2GB
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
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
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
2,364 Expert 2GB
Quite welcome, Tom...
Mar 17 '07 #15
Dököll
2,364 Expert 2GB
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
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
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
2,364 Expert 2GB
Fantastic, I am glad...Good luck with the project, Tom :-)

In a bit!

Dököll
Mar 18 '07 #19

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

Similar topics

10
by: Stefan Höhne | last post by:
Hi, as I recon, std::vector::clear()'s semantics changed from MS VC++ 6.0 to MS' DOT.NET - compiler. In the 6.0 version the capacity() of the vector did not change with the call to...
21
by: DraguVaso | last post by:
Hi, I have an inherited DataGrid, that does lots of extra stuff. For exemple drawing a backgroundimage in every cell. The problem is that it's taking too much time (using gdi+), so I want to do...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
6
by: helpless newbie | last post by:
Hello. I'm a newbie in c programming. I'd like to make a program for creating an image file from a floppy disk. Is there anyone with agood point of start in doing this? Thanks.
2
by: Tomomichi Amano | last post by:
Hello How can I delete (clear) lines that were made useing Graphics.DrawLine() ? Thanks in advance! Have a nice day!
1
by: laurakr | last post by:
I am trying to use a clear to get my bottom nav bar below the quote box on the right, but it isn't working. I would like the bottom edge of the quote box to "stick" to the footer nav bar but copy...
5
by: Brad Pears | last post by:
I have the following code which I was using to print .pdf's. It worked fine and actually printed the pdf file. Now I want to use the same code to print a .jpg file. When I run the code, it...
4
imrosie
by: imrosie | last post by:
Hello all, I'm a YAN (yet another newbie) in need of help. I've got an image database all setup and working fine now, thanks to the help you've given me. In the main form a user can search for an...
1
lotus18
by: lotus18 | last post by:
Hello I'm using vb6 and CR 11. How to manage Image in CR? I inserted an image in the Report Header (ReportHeader Section1), then when I run it, the image size is not the same as during the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.