![]() |
Listbox färbt komisch ein
ich weiss ein viel diskutiertes Thema. dennoch komm ich auch nach dem Studium von x threads hier im Forum nicht weiter.
in meiner Listbox möchte ich ausgewählte Einträge einfärben. habe die listboxdrawitem procedure wie folgt angepasst:
Delphi-Quellcode:
der richtige Eintrag wird zwar auch richtig eingefärbt, jedoch ziemlich "verstümelt" - bei allen anderen zeilen habe ich nur noch das Wort des Eintrags markiert und gefärbt. Der Rest ist ein komischer Rahmen und alle sein bisschen schief. Ich weiss nicht wie ich das beschreiben soll?!
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (control as TListBox) do begin if Index = 2 then //bei best. Zeile soll folgendes gelten begin Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; Canvas.Rectangle(Rect); end; Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; habe bei der Listbox eingestellt: lbOwnerDrawFixed Die Einträge fülle ich normal mit listbox.items.add ein. kann mir einer sagen warum das so komisch aussieht? |
Re: Listbox färbt komisch ein
So besser?
Delphi-Quellcode:
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (control as TListBox) do begin if Index = 2 then //bei best. Zeile soll folgendes gelten begin Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; Canvas.FillRect(Rect); end else begin //falls gewünscht Canvas.Brush.Color := clWhite; Canvas.Pen.Color := clBlack; Canvas.FillRect(Rect); end; Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; |
Re: Listbox färbt komisch ein
Liste der Anhänge anzeigen (Anzahl: 1)
dann mach doch mal einen screenshoot und häng das mal dran ...
habs mal kurz ausprobiert, mit lbOwnerDrawFixed gibt folgender code das ergebnis lt. anhang...
Delphi-Quellcode:
und ich find das ganz in ordnung so ... :stupid:
procedure TForm1.FormCreate(Sender: TObject);
var i: integer; begin for i := 0 to 10 do ListBox1.AddItem('item: ' + inttostr(i), NIL); end; procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); begin if control is tListbox then begin with control as tListbox do begin if Index mod 2 = 0 then //bei best. Zeile soll folgendes gelten begin Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; Canvas.Rectangle(Rect); end; Canvas.TextOut(Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; |
Re: Listbox färbt komisch ein
Zitat:
der rahmen mit der farbe passt allerdings... |
Re: Listbox färbt komisch ein
Zitat:
|
Re: Listbox färbt komisch ein
wie siehts denn aus? häng doch mal einen screenshoot an und am besten ein kleines testporjekt dazu (.pas, .dpr und .dfm). ausserdem wäre es ganz interessant, mit welchem betriebssystem das ganze probleme bereitet und ggf. die grafikkarte dazu (hier sind ausgesprochende grfxkartenspezialisten, die gleich sagen können ob es daran liegt).
|
Re: Listbox färbt komisch ein
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (Control as TListBox) do begin if Index = 2 then //bei best. Zeile soll folgendes gelten begin Canvas.FillRect(Rect); Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; end else begin //falls gewünscht Canvas.FillRect(Rect); Canvas.Brush.Color := clWhite; Canvas.Pen.Color := clBlack; end; Canvas.Font.Color := clWindowText; // <- diese Zeile noch hinzufügen. Dann ist die Schrift nicht mehr "weiss" Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; |
Re: Listbox färbt komisch ein
Zitat:
Die ist jetzt transparent und somit sieht man relativ schlecht welche Zeile ausgewählt ist. Der Rest passt schon ganz gut muss ich sagen! Verwende Vista hier und in der Firma XP. Die Auswirkungen waren bei beiden Systemen die gleichen. |
Re: Listbox färbt komisch ein
Zitat:
Ein cooles Tool vorallem für alle Vista Besitzer... :) |
Re: Listbox färbt komisch ein
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (Control as TListBox) do begin if Index = 2 then //bei best. Zeile soll folgendes gelten begin Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; end else begin //falls gewünscht Canvas.Brush.Color := clWhite; Canvas.Pen.Color := clBlack; end; if (odSelected in State) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else Canvas.Font.Color := clWindowText; Canvas.FillRect(Rect); Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; |
Re: Listbox färbt komisch ein
Zitat:
und: wenn ich mit der maus klicke werden die farben dargestellt. jedoch nicht beim laden der listbox bzw. beim laden des forms. wie kann ich die listbox IMMER farbig halten? |
Re: Listbox färbt komisch ein
Delphi-Quellcode:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (Control as TListBox) do begin if Index = 2 then begin //bei best. Zeile soll folgendes gelten Canvas.Brush.Color := clRed; Canvas.Font.Color := clYellow; end else //falls gewünscht Canvas.Pen.Color := clyellow; if (odSelected in State) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end; Canvas.FillRect(Rect); Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; Zitat:
Delphi-Quellcode:
Sobald sich der Wert ändert, musst du die Listbox neu zeichnen lassen. z.B per ListBox1.Repaint
if Index = 2 then
|
Re: Listbox färbt komisch ein
Zitat:
Delphi-Quellcode:
die Aktuelle Prozedur sieht so aus. Ich reagiere auf Settings in einem Ini-File. Wenn ich den listbox1.repaint beim Laden der Listbox einfüge (am Schluss) wird diese aber nicht korrekt farblich markiert...
procedure Tmainform.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState); begin with (Control as TListBox) do begin if getinivaluefrom(inttostr(listbox1.itemindex+1),'Active',getinivalue('StandardValues','TaskFile'))='false' then //bei best. Zeile soll folgendes gelten begin Canvas.Brush.Color := clRed; Canvas.Pen.Color := clWhite; end else begin //falls gewünscht Canvas.Brush.Color := clWhite; Canvas.Pen.Color := clBlack; end; if (odSelected in State) then begin Canvas.Font.Color := clHighlightText; Canvas.Brush.Color := clHighlight; end else Canvas.Font.Color := clWindowText; Canvas.FillRect(Rect); Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, Items[Index]); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:47 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