如何在 TSpeedButton 上显示 gif
How to show gif on TSpeedButton
按照我之前提出的问题; How do I display two images consecutively like a gif?,有人告诉我可以创建一个 gif
。
这是我的理由:tspeedbutton 不接受 .gif
延期。
如何添加?
btnNotification.Glyph.LoadFromFile(ICON_DIR + '/notification-active.gif');
我用谷歌搜索但由于 Delphi 找不到文档。
您好,
实际上我正在尝试创建通知按钮。如果没有通知,它的图像是 notification.bmp 但如果有通知,它应该是 tspeedbutton 上的 gif。我添加了一个计时器并轮询服务器,是否有任何通知给我?每 6 秒,如果是,我需要在 tspeedbutton
上将 bmp 图像更改为 gif
要以干净的方式执行此操作,我建议您构建一个新组件。幸运的是,有一个组件是 TSpeedButton
并接受任何类型的 TPicture
作为它的 Glyph
属性,我们所要做的就是修改它来激活 Glyph如果是 GIF
所以从接受的答案中复制 TNCRSpeedButton
的单位
转到以下过程并将行添加到代码中(或者只用那个替换这个过程)。
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;
现在该组件在接收到 TGIFImage
作为其字形时会对其进行动画处理。
按照我之前提出的问题; How do I display two images consecutively like a gif?,有人告诉我可以创建一个 gif
。
这是我的理由:tspeedbutton 不接受 .gif
延期。
如何添加?
btnNotification.Glyph.LoadFromFile(ICON_DIR + '/notification-active.gif');
我用谷歌搜索但由于 Delphi 找不到文档。
您好,
实际上我正在尝试创建通知按钮。如果没有通知,它的图像是 notification.bmp 但如果有通知,它应该是 tspeedbutton 上的 gif。我添加了一个计时器并轮询服务器,是否有任何通知给我?每 6 秒,如果是,我需要在 tspeedbutton
上将 bmp 图像更改为 gif要以干净的方式执行此操作,我建议您构建一个新组件。幸运的是,有一个组件是 TSpeedButton
并接受任何类型的 TPicture
作为它的 Glyph
属性,我们所要做的就是修改它来激活 Glyph如果是 GIF
所以从接受的答案中复制 TNCRSpeedButton
的单位
转到以下过程并将行添加到代码中(或者只用那个替换这个过程)。
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;
现在该组件在接收到 TGIFImage
作为其字形时会对其进行动画处理。