Difference between revisions of "Changing application Icon"

From Lazarus wiki
Jump to navigationJump to search
m (Fixed syntax highlighting)
 
Line 1: Line 1:
<source>
+
<syntaxhighlight lang="pascal">
 
unit main;
 
unit main;
  
Line 57: Line 57:
  
 
end.
 
end.
</source>
+
</syntaxhighlight>
 +
 
 +
[[Category:Code Snippets]]

Latest revision as of 02:38, 7 February 2020

unit main;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Image1: TImage;
    ImageList1: TImageList;
    Timer1: TTimer;
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    FIndex: Integer;
    procedure ChangeIcon(const AIndex: Integer);
  public

  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.ChangeIcon(const AIndex: Integer);
begin
  ImageList1.GetBitmap(AIndex, Image1.Picture.BitMap);
  Application.Icon.Assign(Image1.Picture.Graphic);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  FIndex := -1;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Inc(FIndex);
  ChangeIcon(FIndex);
  if FIndex = ImageList1.Count - 1 then
    FIndex := -1;
end;

end.