![]() |
BlinkLabel Komponente erstellen - Blink Problem
Hallo,
ich möchte eine BlinkLabel Komponente abgeleitet von TLabel erstellen. Soweit funktioniert auch alles. Das Problem was ich habe ist, dass ich nur zur Laufzeit ein blinken haben will. Momentan habe ich auch ein Blinken zur Entwurfszeit. Dieser BlinkLabel ist nicht nur ein einfaches Blinken mit Visible:=not Visible (dies funktioniert auch), sondern ein Wechsler von Farben. Über BlinkMode kann man dann entscheiden, ob man ein Blinken haben will, welches über Visible:=not Visilbe läuft oder ein Blinken, in dem die Farben wechseln.
Delphi-Quellcode:
Kann mir hier jemand helfen?
unit MJBlinkLabel;
interface uses Windows, Messages, SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Graphics; type TBlinkMode = (bmRealBlink, bmFontStyle); type TMJBlinkLabel = class(TLabel) private FBlinkMode: TBlinkMode; FBlink: Boolean; FBlinkValue: Boolean; FTimer: TTimer; FBlinkInterval: Cardinal; FBlinkFontColor: TColor; FBlinkFontStyle: TFontStyles; TmpColor: TColor; TmpStyle: TFontStyles; procedure SetBlink(Value: Boolean); procedure SetBlinkInterval(Value: Cardinal); { Private-Deklarationen } protected procedure OnTimerEvent(Sender: TObject); dynamic; { Protected-Deklarationen } public constructor Create(AOwner: TComponent); override; destructor Destroy; override; { Public-Deklarationen } published property BlinkMode: TBlinkMode read FBlinkMode write FBlinkMode; property Blink: Boolean read FBlink write SetBlink; property BlinkInterval: Cardinal read FBlinkInterval write SetBlinkInterval; property BlinkFontColor: TColor read FBlinkFontColor write FBlinkFontColor; property BlinkFontStyle: TFontStyles read FBlinkFontStyle write FBlinkFontStyle; { Published-Deklarationen } end; procedure Register; implementation procedure Register; begin RegisterComponents('Extras', [TMJBlinkLabel]); end; constructor TMJBLinkLabel.Create(AOwner: TComponent); begin inherited Create(AOwner); FBlink:=False; FBlinkInterval:=500; FBlinkFontColor:=clRed; FBlinkFontStyle:=[fsBold]; FTimer:=TTimer.Create(Self); FTimer.OnTimer:=OnTimerEvent; FTimer.Enabled:=False; FTimer.Interval:=500; end; destructor TMJBLinkLabel.Destroy; begin FTimer.Free; inherited Destroy; end; procedure TMJBLinkLabel.OnTimerEvent(Sender: TObject); begin FBlinkValue:=not FBlinkValue; //in dieser Prozedur liegt das Problem If FBlink = True then //wird schon zur Entwurfszeit ausgeführt, wenn Blink True ist begin //ich möchte es aber erst zur Laufzeit Blinken sehen TmpColor:=Font.Color; TmpStyle:=Font.Style; Font.Color:=FBlinkFontColor; Font.Style:=FBlinkFontStyle; end Else begin Font.Color:=TmpColor; Font.Style:=TmpStyle; end; end; procedure TMJBlinkLabel.SetBlink(Value: Boolean); begin If FBlink <> Value then begin FBlink:=Value; FTimer.Enabled:=Value; end; end; procedure TMJBlinkLabel.SetBlinkInterval(Value: Cardinal); begin If FBlinkInterval <> Value then begin FBlinkInterval:=Value; FTimer.Interval:=Value; end; end; end. Gruß Mazel |
Re: BlinkLabel Komponente erstellen - Blink Problem
Hi,
mit:
Delphi-Quellcode:
du kannst einfach überprüfen, ob sich dein Programm gerade in der Designzeit oder Laufzeit befindet.
if csDesigning in ComponentState
Mein Vorschlag, einfach im Constructor:
Delphi-Quellcode:
Das müsste eigentlich funktionieren....
FTimer.Enabled := not (csDesigning in ComponentState);
//Edit: Sehe gerade, dass du den Timer in SetBlink aktivierst - dann müsstest du den Code so abändern:
Delphi-Quellcode:
procedure TMJBlinkLabel.SetBlink(Value: Boolean);
begin If FBlink <> Value then begin FBlink:=Value; FTimer.Enabled:=Value and not (csDesigning in ComponentState); end; end; |
Re: BlinkLabel Komponente erstellen - Blink Problem
Hey,
danke Martin. Das funktioniert super. :thumb: Das ich das Abfragen kann, ob ich mich im Designmodus befinde habe ich nicht gewusst. Danke nochmal. Gruß Mazel |
Re: BlinkLabel Komponente erstellen - Blink Problem
Alternativ kannst Du auch einfach im OnTimer-Egeigniss prüfen:
Delphi-Quellcode:
procedure TMJBLinkLabel.OnTimerEvent(Sender: TObject);
begin if not (csDesigning in ComponentState) then begin FBlinkValue:=not FBlinkValue; //in dieser Prozedur liegt das Problem If FBlink then //wird schon zur Entwurfszeit ausgeführt, wenn Blink True ist begin //ich möchte es aber erst zur Laufzeit Blinken sehen TmpColor:=Font.Color; TmpStyle:=Font.Style; Font.Color:=FBlinkFontColor; Font.Style:=FBlinkFontStyle; end else begin Font.Color:=TmpColor; Font.Style:=TmpStyle; end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:18 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz