![]() |
AW: ListBox
Ich komm nicht dahinter... Aber trotzdem danke für die Hilfe
|
AW: ListBox
Hat eigentlich schon jemand erwähnt, daß der Threadtitel absolut nichts zum Problem aussagt?
Und ja, es gibt schon massig Themen, wo irgendwer irgendwelche Probleme mit seiner ListBox hat. |
AW: ListBox
Nur sinngemäß, da ich gerade kein Delphi offen habe, geht bestimmt auch einfacher:
Delphi-Quellcode:
type
TLBColor=class public Color:TColor; end; //Item zur Liste hinzufügen: procedure TForm1.Button1Click(Sender: TObject); var t:TLBColor; begin t:=TLBColor.Create; t.Color:=clWhite; Listbox1.AddItem('foo',t); end; //in deiner Prüffunktion while i < Form1.ListBox1.Count do begin userId := sqlst.query('select id from user_ where username = '''+Form1.listbox1.Items[i]+''''); //user not found if userId = '' then //Change Color of current line - cLYellow TLBColor(Listbox1.Items.Objects(i)).Color:=clRed; i := i + 1; end; procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState) ; var myColor: TColor; myBrush: TBrush; begin myBrush := TBrush.Create; with (Control as TListBox).Canvas do begin myColor := TLBColor(Listbox1.Items.Objects(index)).Color; myBrush.Style := bsSolid; myBrush.Color := myColor; Windows.FillRect(handle, Rect, myBrush.Handle) ; Brush.Style := bsClear; TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]) ; MyBrush.Free; end; end; |
AW: ListBox
Jetzt hab ichs kapiert.... funktioniert!
Danke an alle für die Geduld! |
AW: ListBox
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
Zum Code. Den muss man nicht so komplex machen wie hier:
Delphi-Quellcode:
Im Grunde reicht es, was Farbe angeht, das:
procedure TForm1.ListBox1DrawItem
(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState) ; var myColor: TColor; myBrush: TBrush; begin myBrush := TBrush.Create; with (Control as TListBox).Canvas do begin myColor := TLBColor(Listbox1.Items.Objects(index)).Color; myBrush.Style := bsSolid; myBrush.Color := myColor; Windows.FillRect(handle, Rect, myBrush.Handle) ; Brush.Style := bsClear; TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]) ; MyBrush.Free; end; end;
Delphi-Quellcode:
Zum empfehlen ist sich an die Listbox ein Objekt mit Infox anzuhängen. Kein großer Aufwand, aber bei OnDrawItem kann man sich die nötigen Infos bezüglich Farbe und weitere Formatierung da rausholen.
begin
with (Control as TListBox).Canvas do begin ... Brush.Color := myColor; ... end; end; Im Anhang habe ich ein kleines Beispiel das zeigt wie das mit dem angehängtem Objekt funktioniert und wie man jeden Item individuell einfärben kann: |
AW: ListBox
Zitat:
|
AW: ListBox
Nach meiner Kenntnis, Beobachtungen und ausführlichen Tests ja. Wobei mit "einmal" nicht einmal pro ListBox, sondern einmal pro Item, und zwar bei Erstellung des jeweiligen Items gemeint ist.
Wie das in neueren Delphis ist, weiß ich nicht, bei Delphi 7 ist es so. Wenn du andere Kenntnis hast oder Möglichkeiten kennst, her damit. |
AW: ListBox
Also eigentlich hätte ich jetzt erwartet, das OnMeasureItem bei jedem Zeichen aufgerufen wird, den die Listbox weiß ja vorher nicht, was sie wie Zeichnen soll.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:22 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