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 Ownerdraw Problem (https://www.delphipraxis.net/142631-listbox-ownerdraw-problem.html)

mcmichael 31. Okt 2009 16:20


Listbox Ownerdraw Problem
 
Hallo liebe Experten,

ich möchte die Einträge in meiner Listbox selber zeichnen,
weil abhängig vom Inhalt die Schriftfarbe gesetzt werden soll.

Also habe ich das Ereignis entsprechend bestückt.
Die Schriftfarbe wird auch entsprechend gesetzt, aber
der Markierungsbalken ist in babyblau.
Ich hätte ihn gern in $00D7D7D7 (irgendwie grau),
aber wenn ich den auskommentierten Code aktiviere, werden alle
Zeilen in grau dargestellt wenn ich durch die Liste scrolle (itemindex+1/-1)

was mach ich denn falsch?


Delphi-Quellcode:
procedure TForm2.ListBox2DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var Offset: Integer;     { text offset width }
     nr:integer;
begin
with (Control as TListBox).Canvas do
  begin
  {if index=(Control as TListBox).itemindex then
    brush.color:=$00D7D7D7
  else
    brush.color:=clWhite;}

  FillRect(Rect);
  Offset := 2;
  font.Style:=[];
  font.Size:=16;
  nr:=StrToInt(copy((Control as TListBox).Items[Index],10,2));
  case nr of
      69: begin
          font.color:=clRed;
          font.Style:=[fsbold];
          end;
      17,22: font.color:=clGray;
      10,13,19,20,31,32,37,53,35,36: font.color:=$000080FF;
      11,12,21,33,52: font.color:=clGreen;
      else font.color:=clBlack;
    end;
  TextOut(Rect.Left + Offset, Rect.Top, (Control as TListBox).Items[Index])
  end
end;

thkerkmann 31. Okt 2009 17:08

Re: Listbox Ownerdraw Problem
 
Hi,

beim Zeichnen der Einträge erkennst Du die Zeile mit dem Markierungsbalken nicht am ItemIndex.
Delphi-Quellcode:
  if index=(Control as TListBox).itemindex then
    brush.color:=$00D7D7D7
  else
    brush.color:=clWhite;
sondern am State

Delphi-Quellcode:
  if odSelected in State then
    brush.color:=$00D7D7D7;
Gruss

mcmichael 1. Nov 2009 10:34

Re: Listbox Ownerdraw Problem
 
grandios, läuft.

Vielen Dank!


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