![]() |
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; |
AW: ListBox Item Farbe bekommen
Müsste das nicht so gehen?
Delphi-Quellcode:
: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.
var
C : TColor; begin Index := ListBox1.ItemIndex; if (Index > -1) and (Index < ListBox1.Count) then begin C := TColor(ListBox1.Objects[Index]); end; end; |
AW: ListBox Item Farbe bekommen
Stimmt :wall: :wall: :wall:
thx |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:20 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