Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TImageList/TSpeedbutton question

911 views
Skip to first unread message

John B

unread,
Aug 3, 2008, 7:37:03 PM8/3/08
to
As I understand it, TSpeedButton can accept images with multiple glyphs
(eg., 1x1, 1x2, 1x3, or 1x4) to represent the different states of the
TSpeedButton. It can also use a TImageList and a reference to display
glyphs. Is there a way to use a TImageList or some other similar component
with different sized images to take advantage of this feature?

Thanks,

John

Peter Below (TeamB)

unread,
Aug 4, 2008, 4:31:25 AM8/4/08
to
John B wrote:

A TSpeedbutton cannot use an image list *directly*. It can be tied to
an imagelist through an action, though. With a bit of fiddling you can
get it to use "multiple glyph" images from an imagelist. This can be
done the following way:

Drop a TImagelist on the form and set it Height to 16 and the Width to
32. Doubleclick on it and use the imagelist editor to add some of the
button glyphs from the images that come with Delphi to the list. Note
that these bitmaps need to be 16*32, you cannot load two 16*16 images
and get the imagelist to treat them as one image. Assign this imagelist
to a TActionlist, add a few actions, set the actions ImageIndex as
needed, drop a couple of speedbuttons or bitbuttons, assign the actions
to each and then set the NumGlyphs property of the buttons to 2. That
is the step not done automatically. The result works as intended
because the buttons make an internal copy of the imagelist image into
their Glyph property (inefficient and wasteful of resources, but that
was the easiest way to implement it in a way that also allows the
buttons to be used without associated actions).

If you want to start with two 16*16 images your best bet is to create
another imagelist (16*16 this time) and load the images into it in the
correct sequence. Then use code to create 16*32 images from those at
run-time and deposit them into a new imagelist set to 16*32 size, then
tie that to the actionlist and set the NumGlyphs properties as
required, also in code. Same applies to 16*48 or 16*64 images, of
course, but you have to decide on one format to use, since a given
imagelist can only hold images that are all of the same size, and an
actionlist can only be tied to one imagelist. Supporting a mixture of
sizes would be a bit cumbersome since you would need a separate
actionlist + imagelist for every image size you want to use.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

John B

unread,
Aug 4, 2008, 8:20:12 PM8/4/08
to
Thanks Peter! I am indeed using a TActionList to load the TSpeedButtons.

What prompted my question was an apparent difference in the way D6 behaved
vs D2007. Based on your response, I think I discovered what happened.

When I initially loaded the TImageList, I mixed 16x16 and 16x32 images,
which actually cropped the longer ones to 16x16. I then assigned the
TImageList to a TActionList, and assigned image references to each of the
actions.

However, in my programming a long time ago, I'm sure I must have reloaded
the 16x32 Glyphs into several TSpeedbuttons (setting NumGlyphs to 2) to get
them to behave properly, which I am sure overrides the TAction glyph.

When I recompiled in D2007, the images weren't displaying properly in the
IDE, so I reset all the TAction links in the TSpeedButtons. This reset the
TSpeedButton glyphs, making the ones set for 2 glyphs to show only half the
image.

Thanks again for your help. I now have two choices:
1) Override the 2-glyph speedbuttons again
2) Create 16x32 glyphs for all the current 16x16 images

John

"Peter Below (TeamB)" <no...@nomail.please> wrote in message
news:xn0ftixp...@newsgroups.borland.com...

0 new messages