![]() |
label mit verschiedenen Farben
Hi,
gibt es eine Möglichkeit in einem label text mit verschiedenen farben darzustellen ? Bsp: rotblaurot Danke Ralf |
Re: label mit verschiedenen Farben
Nicht mit dem Standard-Label, das hat nur eine Schriftfarbe. Vielleicht schaust du mal bei Torry oder den Jedi's irgendwo gibt's da sicher schon eine fertige Komponenete für.
z.B. ![]() |
Re: label mit verschiedenen Farben
Delphi-Quellcode:
Das solltest du "override"...
procedure TCustomLabel.Paint;
const Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER); WordWraps: array[Boolean] of Word = (0, DT_WORDBREAK); var Rect, CalcRect: TRect; DrawStyle: Longint; begin with Canvas do begin if not Transparent then begin Brush.Color := Self.Color; Brush.Style := bsSolid; FillRect(ClientRect); end; Brush.Style := bsClear; Rect := ClientRect; // DoDrawText takes care of BiDi alignments DrawStyle := DT_EXPANDTABS or WordWraps[FWordWrap] or Alignments[FAlignment]; // Calculate vertical layout if FLayout <> tlTop then begin CalcRect := Rect; DoDrawText(CalcRect, DrawStyle or DT_CALCRECT); if FLayout = tlBottom then OffsetRect(Rect, 0, Height - CalcRect.Bottom) else OffsetRect(Rect, 0, (Height - CalcRect.Bottom) div 2); end; DoDrawText(Rect, DrawStyle); end; end; function TCustomLabel.GetLabelText: string; begin Result := Caption; end; procedure TCustomLabel.DoDrawText(var Rect: TRect; Flags: Longint); var Text: string; begin Text := GetLabelText; if (Flags and DT_CALCRECT <> 0) and ((Text = '') or FShowAccelChar and (Text[1] = '&') and (Text[2] = #0)) then Text := Text + ' '; if not FShowAccelChar then Flags := Flags or DT_NOPREFIX; Flags := DrawTextBiDiModeFlags(Flags); Canvas.Font := Font; if not Enabled then begin OffsetRect(Rect, 1, 1); Canvas.Font.Color := clBtnHighlight; DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags); OffsetRect(Rect, -1, -1); Canvas.Font.Color := clBtnShadow; DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags); end else DrawText(Canvas.Handle, PChar(Text), Length(Text), Rect, Flags); end; type TMyLabel = class(TLabel) end; |
Re: label mit verschiedenen Farben
Wow, dass ging ja turboschnell
Danke für die Hilfe Ralf |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:11 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