TImageLists and TMenuItems - bitmaps

Hi Folks,

I've got a TActionList filled with actions I want to use.  At times, these actions maybe disabled.  If I use a TSpeedButton, and set it's action property to one of my actions, the bitmap changes.  If I set the action to Enabled := false, the bitmap disappears.  This is because I'm using a 16x16 bitmap with only a signle state (and NumGlyphs set to 1 for the SpeedButton).

If I change the ImageList to contain 32x16 glyphs, change the TSpeedButtons to use NumGlpyhs := 2, then all works well when I enable or disable the action.

Except for the menu items.  The menu items show two images - the enabled and disabled state - per item.

My question is, how do you use the same ImageList and Action list to work with both TSpeedButtons and TMenuItems?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wim ten BrinkSelf-employed developerCommented:
Don't! Sorry...
Link the MainMenu component to an imagelist with 16x16 images and the actionlist to the 32x16 imagelist.
It is possible to create the 16x16 imagelist dynamically based upon the other imagelist. All you have to do is walk through the images in the 32x16 imagelist and add those images to the 16x16 imagelist, in the FormCreate event.
Eddie ShipmanAll-around developerCommented:
How can you tell him to not use the same imagelist?
We currently use 16x16 images in our imagelist and assign the actions to BOTH menus and speedbuttons.
We see no problems with the disabled images on all but one of the glyphs.

Delphi should create the disabled bitmap on the fly when it doesn't have one.

If he "copies" the 32x16 images to the 16x16 imagelist he will need to delete every odd image before being
able to use it effectively because the imagelist will contain disabled bitmaps in the odd indexes.

Wim ten BrinkSelf-employed developerCommented:
Simple... TMenu can be linked to a different imagelist than the TActionList. His problem is theneed for 32x16 with TBitBtn and 16x16 for TMenu. So NO 16x16 images for the buttons! Of course, Delphi will create the disabled image if it's missing but what if he doesn't want this disabled image???
My suggestion is just one imagelist with the images in 32x16 and a second, empty imagelist which will be filled with 16x16 images in runtime, if some code to do this is written.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Eddie ShipmanAll-around developerCommented:
I was just saying that he doesn't need the 32x16 imagelist due to Delphi creating the disabled images for him.
I would think that having two imagelists with practically the same images is a bit of overhead for any program.
Stuart_JohnsonAuthor Commented:
The disabled images weren't being created for me automatically which is why I'm using 32x16.  I thought delphi automatically created the disabled glyphs, but it's not.

If I create a TSpeedButton and put a 16x16 _16 COLOUR_ glyph on it, it renders a disabled glyph perfectly.  If I use a 256 colour glyph (which is what I'm using), it doesn't create the disabled glyph.

I'll use Alex's code because that worked perfectly.  I just setup a secondary image list during formcreate.

Thanks for the input guys.

Thanks, Alex.

Stuart_JohnsonAuthor Commented:
Sorry for the delay in getting back to this question.  I've been away.

Thanks again, Alex.

Wim ten BrinkSelf-employed developerCommented:
Don't worry about the delay. Thanks for the points. :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.