1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| unit uLabelClignot;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,
extctrls; //<- ajouté pour les TTimer''s
// QExtCtrls <- n''existe pas sous Delphi5
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TFlashLabel = class(TCustomLabel)
private
{ Déclarations privées }
Ftimer :TTimer;
Ffrequence :Cardinal;
Fflashing :Boolean;
procedure SetFlashing(const isFlashing :Boolean);
procedure SetFrequence(const Afrequence :Cardinal);
procedure TmrTimer(Sender: TObject);
public
{ Déclarations publiques }
constructor Create(AOwner: TComponent); override;
//destructor Destroy; override;
property Flashing :Boolean read Fflashing write SetFlashing default True;
property Frequence :Cardinal read Ffrequence write SetFrequence default 1000;
end;
{ TFlashLabel }
constructor TFlashLabel.Create(AOwner: TComponent);
begin
inherited;
Fflashing := True;
Ffrequence := 1000;
Ftimer := TTimer.Create(Self);
Ftimer.Enabled := Fflashing;
Ftimer.Interval := Ffrequence;
Ftimer.OnTimer := TmrTimer;
end;
//destructor TFlashLabel.Destroy;
//begin
// Ftimer.Free;
// inherited;
//end;
procedure TFlashLabel.SetFlashing(const IsFlashing: Boolean);
begin
Fflashing := IsFlashing;
if not Fflashing then
Visible := True;
Ftimer.Enabled := IsFlashing;
end;
procedure TFlashLabel.SetFrequence(const Afrequence: Cardinal);
begin
Ffrequence := Afrequence;
Ftimer.Interval := Afrequence;
end;
procedure TFlashLabel.TmrTimer(Sender: TObject);
begin
Visible := not Visible;
end;
var
FshLbl :TFlashLabel;
procedure TForm1.FormCreate(Sender: TObject);
begin
FshLbl := TFlashLabel.Create(Self);
FshLbl.Parent := Self;
FshLbl.SetBounds(50, 50, 200, 20);
FshLbl.Caption := 'COUCOU...COUCOU...COUCOU';
FshLbl.Visible := True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
FshLbl.Flashing := not FshLbl.Flashing;
if FshLbl.Flashing then
TButton(Sender).Caption := 'label statique'
else
TButton(Sender).Caption := 'label dynamique';
FshLbl.Frequence := StrToIntDef(edit1.Text, 1000);
end;
END. |
Partager