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 Item Farbe bekommen (https://www.delphipraxis.net/167648-listbox-item-farbe-bekommen.html)

gelberkaktus 11. Apr 2012 12:05

ListBox Item Farbe bekommen
 
Hallo,

ich möchte die ListBoxeinträge meines Programms farbig machen und ies soll gespeichert werden.

Nun habe ich folgendes Problem: Wie bekomme ich die Farbe des ListBoxItems ausgelesen?

Delphi-Quellcode:
//Prozedur zum Einfärben des Items
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);

begin
  with Control as TListBox do
  begin
    Canvas.FillRect(Rect);
    Canvas.Font.Color := TColor(Items.Objects[Index]);
    Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]);
  end;

end;
//Prozedur die den Inhalt eines Edit-feldes in der Farbe die man im Colordialog ausgewählt hab färbt
procedure TForm1.Button2Click(Sender: TObject);

begin

if ColorDialog1.Execute then
ListBox1.Items.AddObject(Edit1.Text, Pointer(ColorDialog1.Color));

end;

//Prozedur die die Farbe des Items ändert
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
text:string;
begin
for i:= 0 to (ListBox1.Count -1) do
begin
if ListBox1.Selected[i] then
begin
text:= ListBox1.Items[i];
ShowMessage(IntToStr(i) + text);
if ColorDialog1.Execute then
ListBox1.DeleteSelected;
ListBox1.Items.InsertObject(i,text, Pointer(ColorDialog1.Color));

end;
end;
end;

s.h.a.r.k 11. Apr 2012 12:12

AW: ListBox Item Farbe bekommen
 
Müsste das nicht so gehen?
Delphi-Quellcode:
var
  C : TColor;
begin
  Index := ListBox1.ItemIndex;
  if (Index > -1) and (Index < ListBox1.Count) then
  begin
    C := TColor(ListBox1.Objects[Index]);

  end;
end;
:wall: Du hast den Code zum auslesen doch auch schon da stehen! Vergleiche mal deine ListBox1DrawItem-Methode mit dem Code, den ich hier gepostet habe.

gelberkaktus 11. Apr 2012 13:23

AW: ListBox Item Farbe bekommen
 
Stimmt :wall: :wall: :wall:

thx


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:02 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