Tuesday, January 09, 2007
BlinkingLabel
Descendent del TLabel que canvia de color intermitentment
unit BlinkingLabel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TBlinkingLabel = class(TCustomLabel)
private
{ Private declarations }
Timer: TTimer;
FBlinkingEnabled: boolean;
FBlinkingInterval: integer;
FBlinkingFirstColor: TColor;
FBlinkingSecondColor: TColor;
procedure RefreshLabel;
protected
{ Protected declarations }
procedure SetBlinkingEnabled(ABlinkingEnabled: boolean);
procedure SetBlinkingInterval(ABlinkingInterval: integer);
procedure OnTimer(Sender: TObject); virtual;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property BlinkingEnabled: boolean read FBlinkingEnabled write SetBlinkingEnabled default True;
property BlinkingInterval: integer read FBlinkingInterval write SetBlinkingInterval default 500;
property BlinkingFirstColor: TColor read FBlinkingFirstColor write FBlinkingFirstColor;
property BlinkingSecondColor: TColor read FBlinkingSecondColor write FBlinkingSecondColor;
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BiDiMode;
property Caption;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FocusControl;
property Font;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowAccelChar;
property ShowHint;
property Transparent;
property Layout;
property WordWrap;
property Visible;
property OnClick;
property OnDblClick;
property OnDragOver;
property OnDragDrop;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;
implementation
constructor TBlinkingLabel.Create(AOwner: TComponent);
begin
FBlinkingEnabled := False;
FBlinkingInterval := 500;
FBlinkingFirstColor := clBlue;
FBlinkingSecondColor := clRed;
Timer := TTimer.Create(Self);
Timer.Enabled := FBlinkingEnabled;
Timer.Interval := FBlinkingInterval;
Timer.OnTimer := OnTimer;
inherited;
RefreshLabel;
end;
destructor TBlinkingLabel.Destroy;
begin
Timer.Free;
inherited;
end;
procedure TBlinkingLabel.SetBlinkingEnabled(ABlinkingEnabled: boolean);
begin
FBlinkingEnabled := ABlinkingEnabled;
Timer.Enabled := ABlinkingEnabled;
end;
procedure TBlinkingLabel.SetBlinkingInterval(ABlinkingInterval: integer);
begin
FBlinkingInterval := ABlinkingInterval;
Timer.Interval := ABlinkingInterval;
end;
procedure TBlinkingLabel.OnTimer(Sender: TObject);
begin
RefreshLabel;
end;
procedure TBlinkingLabel.RefreshLabel;
begin
if Font.Color=FBlinkingFirstColor then
Font.Color := FBlinkingSecondColor
else
Font.Color := FBlinkingFirstColor;
end;
procedure Register;
begin
RegisterComponents('Components Delphi', [TBlinkingLabel]);
end;
end.
Les propietats BlinkingFirstColor i BlinkingSecondColor indiquen els dos colors entre els quals s'alterna. La propietat BlinkingInterval indica el període de canvi en milisegons. Amb la propietat BlinkingEnabled activem o desactivem el canvi.