![]() |
Listbox - einzelne Itemstrings farbig kennzeichnen?
Moin,
wie kann ich in einer Komponente Listbox einzelne Elemente farbig kennzeichnen? Beispiel: ich habe Item 1 Item 2 Item 3 ... Item 9 Der Text von Item 2 soll grün und der von Item 9 rot sein. Hat jemand eine Idee? Gruss EL |
Re: Listbox - einzelne Itemstrings farbig kennzeichnen?
Stye := lbOwnerDrawFixed
ListBox1.OnDrawItem ... |
Re: Listbox - einzelne Itemstrings farbig kennzeichnen?
Hai EL,
hier ist mal ein Beispiel bei dem ich die "FarbInformation" in der Object eigenschaft der Items hinterlege:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var ndx: Integer; farbe : Integer; begin ListBox1.Style := lbOwnerDrawFixed; ListBox1.Clear; for ndx := 0 to 20 do begin Case ndx of 0,4,7,9,18 : farbe := clred; 1,6,13,17 : farbe := clgreen; else farbe := clBlack; end; ListBox1.AddItem(IntToStr(ndx),TObject(farbe)); end; end; procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin with (Control as TListbox) do begin Canvas.Font.Color := Integer(Items.Objects[index]); Canvas.TextRect(Rect, Rect.Left+2, Rect.Top, Items[Index]); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09: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-2025 by Thomas Breitkreuz