[DUG] Assigned image to SpeedButton not transparent
Ross Levis
ross at stationplaylist.com
Sat Oct 31 16:28:41 NZDT 2015
Tried that but it didn’t do anything. I tried Button.Invalidate afterwards and that did something strange where the image turned black while the button was in the Down state. Never mind.
I’ve found something that works. Store 2 TImage’s on the form with Visible False and Button.Glyph := Image1.Picture.Bitmap works correctly.
From: delphi-bounces at listserver.123.net.nz [mailto:delphi-bounces at listserver.123.net.nz] On Behalf Of Jolyon Direnko-Smith
Sent: Friday, 30 October 2015 5:22 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Assigned image to SpeedButton not transparent
Retrieving the bitmap from an image list in the way that you are should preserve transparency, if the transparency is correctly set in the image list itself.
However, assigning a bitmap to the Glyph property in this way invokes a behaviour in the Speedbutton class which may be interfering with things.
If your bitmap is a simple, single image (rather than one of the composite images that a speedbutton glyph can support) then you could try simply getting the bitmap directly into the glyph:
ImageList.GetBitmap( N, SpeedButton.Glyph) );
This causes the ImageList to draw the requested image directly onto the canvas of the specified bitmap, bypassing the setter behaviour in the speedbutton. if this is what is mangling the transparency then this may solve your problem.
hth
On 30 October 2015 at 15:51, Ross Levis <ross at stationplaylist.com> wrote:
Using D7/themes, I have a TSpeedButton which is a toggle and I need to display 2 different glyphs in a TSpeedButton based on whether the button was clicked or right-clicked, as they do 2 slightly different things.
So I need to assign a glyph to the button at run time, which works, but nothing I do makes the image transparent. There is always a white square with the icon in the middle. It only looks correct if I assign one of the images to the Glyph property at design time.
I use a TImageList to store the 2 images, and assign them like this as required.
BitMap := TBitMap.Create;
ImageList.GetBitmap(n,BitMap);
SpeedButton.Glyph := BitMap;
BitMap.Free;
where n is 0 or 1.
I've tried setting Bitmap.Transparent to true and other combinations like TransparentMode and TransparentColor but nothing makes any difference.
There is some sort of transparency happening since the images have quite a colorful background but this appears as white on the button.
As a test I assigned the image from a filename Button.Glyph.LoadFromFile() and this works correctly and looks good, but I don't want to distribute BMP files separately.
A possible alternative I haven’t tried is embedding the 2 images as a resource in the EXE file and using Button.Glyph.LoadFromResourceName (or ResourceID), but that seems a lot of work. I thought I would try here to see if anyone knows how to resolve the current method.
Cheers,
Ross.
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at listserver.123.net.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at listserver.123.net.nz with Subject: unsubscribe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20151031/8dc09810/attachment.html
More information about the Delphi
mailing list