Reputation: 1743
Following my previously asked question; How do I display two images consecutively like a gif?, I was told that I could create a gif
.
Here is my reason: tspeedbutton does not accept .gif
extension for me.
How can I add this?
btnNotification.Glyph.LoadFromFile(ICON_DIR + '/notification-active.gif');
I googled but couldn't find documentation because of Delphi.
Hello,
Actually i am trying to create Notification button. If there is no notification, its image is notification.bmp but if there is notification, it should be gif on tspeedbutton. I added a timer and polling the server, is there any notification for me ? in every 6 seconds, if yes i need to change bmp image to gif on tspeedbutton
Upvotes: 1
Views: 414
Reputation: 2591
to do this in a clean way I recommend that you build a new component. luckily there is a component that is a TSpeedButton
and accepts any type of TPicture
as its Glyph
property, all what we have to do is to modify it to animate the Glyph if it was a GIF
So copy the unit of the TNCRSpeedButton
from the accepted answer here
go to the following procedure and add the lines to the code (or just replace this procedure with that one).
procedure TNCRSpeedButton.GlyphChanged(Sender: TObject);
begin
if (FGlyph.Graphic <> nil) and (not FGlyph.Graphic.Empty) then
begin
FGlyphCoordinates.OnChange := nil; // Prevent multiple invalidates
FGlyphCoordinates.X := (Width - FGlyph.Graphic.Width) div 2;
FGlyphCoordinates.Y := (Height - FGlyph.Graphic.Height) div 2;
FGlyphCoordinates.OnChange := CoordinatesChanged;
///// add these lines here ///////////////////////////////////
if (FGlyph.Graphic is TGifImage) then
begin
(FGlyph.Graphic as TGifImage).Animate := True;
end;
//////////////////////////////////////////////////////////////
end;
Invalidate;
end;
now the component when recieved a TGIFImage
as its Glyph it will animate it.
Upvotes: 1