AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

ListBox Item Farbe bekommen

Ein Thema von gelberkaktus · begonnen am 11. Apr 2012 · letzter Beitrag vom 11. Apr 2012
Antwort Antwort
gelberkaktus

Registriert seit: 18. Mär 2012
Ort: Kölleda/Thüringen
16 Beiträge
 
Delphi 7 Personal
 
#1

ListBox Item Farbe bekommen

  Alt 11. Apr 2012, 12:05
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;
"Ohne konkrete Symbole ist der Computer bloß ein Haufen Schrott."
Neil Postman
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#2

AW: ListBox Item Farbe bekommen

  Alt 11. Apr 2012, 12:12
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;
Du hast den Code zum auslesen doch auch schon da stehen! Vergleiche mal deine ListBox1DrawItem-Methode mit dem Code, den ich hier gepostet habe.
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)
  Mit Zitat antworten Zitat
gelberkaktus

Registriert seit: 18. Mär 2012
Ort: Kölleda/Thüringen
16 Beiträge
 
Delphi 7 Personal
 
#3

AW: ListBox Item Farbe bekommen

  Alt 11. Apr 2012, 13:23
Stimmt

thx
"Ohne konkrete Symbole ist der Computer bloß ein Haufen Schrott."
Neil Postman
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:14 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