Releasing memory while adding new images

Nikolis

New Member
Joined
Sep 12, 2022
Messages
27
Office Version
  1. 2007
Platform
  1. Windows
Maybe a silly topic, but I'm still novice and quite unsure about some details.

I have a Userform. Left side column has the menu, consisting of 7 options/"buttons". Those buttons are actually images which change when their area is hovered. E.g. they are originally blue, the hovered state is green. So, the blue button is visible and loaded, then something is hovered, and the "green image appears". Then again blue (while usually something else is turning green) etc.

Now, in every switch from green to blue (or vice versa) I suppose that an extra image's memory is being added to the system's memory.
(1) is this correct or are they just added (once and for all) only the first time they are loaded ?
(2) if this is correct, how may I release memory while "Mouse Move" ? E.g. blue image switches to green, now green occupies memory but blue image's occupied memory is now unneeded and somehow released etc.

Can someone explain how this works ?
Thank you in advance.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If you are placing the buttons above each other at design time and then toggling the buttons visibilty when hovered then the images are loded once .

If you add the images at runtime via code then each image is loaded\unloaded when the buttons are hovered.

If you are using plain color images, why not just change the buttons backcolor property instead of using images ? That would be easier and require less memory.
 
Upvote 0
If you are placing the buttons above each other at design time and then toggling the buttons visibilty when hovered then the images are loded once .

If you add the images at runtime via code then each image is loaded\unloaded when the buttons are hovered.

If you are using plain color images, why not just change the buttons backcolor property instead of using images ? That would be easier and require less memory.
Thank you Jaafar.

Changing the backcolor property is the simplest way but it's limited design-wise. Hence the need to load images, e.g. designed in Photoshop or even Powerpoint.

Can you please define this ; you mention that if I "add the images at runtime via code they are loaded/unloaded", depending on the hover. Now, I know hot to load them. But what about the unloading part ; is it some code I should write (e.g. like Unload Userform1 / Unload Me etc.) or is it handled automatically by VB ?
 
Upvote 0
LoadPicture should unload the previous image and load the new one.

example:
Ctrl.Picture = LoadPicture("C:\images\Img1.bmp")

BTW, how are you setting the buttons images ? are you using the the button's MouseMove event ? I am asking because there is no MouseLeave event for resetting the initial image.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top