Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Listbox - einzelne Itemstrings farbig kennzeichnen? (https://www.delphipraxis.net/50528-listbox-einzelne-itemstrings-farbig-kennzeichnen.html)

emsländer 27. Jul 2005 09:04


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

barf00s 27. Jul 2005 09:08

Re: Listbox - einzelne Itemstrings farbig kennzeichnen?
 
Stye := lbOwnerDrawFixed
ListBox1.OnDrawItem ...

Sharky 27. Jul 2005 09:31

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 11:04 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz