AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Label Font Color Farbwechsel

Ein Thema von BennyM · begonnen am 10. Nov 2005 · letzter Beitrag vom 9. Jun 2007
Antwort Antwort
Benutzerbild von Matze
Matze
(Co-Admin)

Registriert seit: 7. Jul 2003
Ort: Schwabenländle
14.929 Beiträge
 
Turbo Delphi für Win32
 
#1

Re: Label Font Color Farbwechsel

  Alt 9. Jun 2007, 21:30
Hallo C.Rae, herzlich willkommen.

Die oben erwähnten Funktionen machen genau das, was du gerne hättest. Ich habe dir mal eben mithilfe dieser einen Code zusammengestrickt:

Delphi-Quellcode:
procedure Delay(Milliseconds: Integer);
var
  Tick: DWord;
  Event: THandle;
begin
  Event := CreateEvent(nil, False, False, nil);
  try
    Tick := GetTickCount + DWord(Milliseconds);
    while (Milliseconds > 0) and
          (MsgWaitForMultipleObjects(1, Event, False, Milliseconds, QS_ALLINPUT) <> WAIT_TIMEOUT) do
    begin
      Application.ProcessMessages;
      if Application.Terminated then Exit;
      Milliseconds := Tick - GetTickcount;
    end;
  finally
    CloseHandle(Event);
  end;
end;

// Farbe zwischen 2 vorgegebenen Farbwerten berechnen
function ColorBetween(C1, C2 : TColor; blend:Real):TColor;
var
  r, g, b : Byte;

  y1, y2 : Byte;
begin
  C1 := ColorToRGB(C1);
  C2 := ColorToRGB(C2);

  y1 := GetRValue(C1);
  y2 := GetRValue(C2);

  r := Round(y1 + (y2-y1)*blend);

  y1 := GetGValue(C1);
  y2 := GetGValue(C2);

  g := Round(y1 + (y2-y1)*blend);

  y1 := GetBValue(C1);
  y2 := GetBValue(C2);

  b := Round(y1 + (y2-y1)*blend);
  Result := RGB(r, g, b);
end;

// Farbe zwischen beliebig vielen vorgegebenen Farbwerten berechnen
function ColorsBetween(colors:array of TColor; blend:Real):TColor;
var
  a : Integer;
  faktor : Real;
begin
  if Length(colors) < 2 then
    raise Exception.Create('ColorsBetween() at least 2 Colors required');

  if blend <= 0.0 then
    Result := colors[0]
  else if blend >= 1.0 then
    Result := colors[High(colors)]
  else
  begin
    a := Trunc(High(colors) * blend);
    faktor := 1.0 / High(colors);

    Result := ColorBetween(colors[a], colors[a+1], (blend-(a * faktor)) / faktor);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 1 to 100 do
  begin
    Label1.Font.Color := ColorsBetween([clBlue, clYellow, clGreen], i / 100);
    Delay(40);
  end;
end;
Falls es ein wenig flackern sollte, dann setze Delphi-Referenz durchsuchenDoubleBuffered des Parent-Controls auf true. Also beispielsweise so (wenn das Label auf Form1 liegt):

Delphi-Quellcode:
// OnCreate
Form1.DoubleBuffered := true;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:14 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-2025 by Thomas Breitkreuz