Autor Beitrag
JVS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Di 03.11.09 21:59 
Hallo an alle,
es gelingt mir, ganze Zeile eines ListViews ( ViewStype=vsReport) mit Hilfe von OnCustomDrawItem unterschiedlich zu färben. Bei den Einzelzellen will es mit Hilfe von OnCustomDrawSubItem nicht klappen.

Im folgenden Beispiel sollen die leeren Zellen farbig hinterlegt werden.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.meinLVCustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  if Item.subitems[subitem-1]<>'' then
    Sender.Canvas.Brush.Color:=clWindow
    else
    Sender.Canvas.Brush.Color:=$00AAEEFF;
end;


Sobald die erste leere Zelle der Zeile erreicht wird, werden auch alle folgenden Zellen dieser Zeile farbig gezeichnet. Wieso das?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Di 03.11.09 22:37 
Mit clWhite geht es.. kann dir grad aber auch nicht sagen, warum das mit clWindow nicht geht. Vielleicht steht das in diesem Zusammenhang für sowas wie durchsichtig?

_________________
PROGRAMMER: A device for converting coffee into software.
JVS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Mi 04.11.09 09:47 
Hi Xentar,
ja, das war es, Danke!
Komischerweise hat clWindowText für Canvas.Font.Color die richtige Wirkung.

Das funktioniert jetzt also perfekt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.meinLVCustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
Sender.Canvas.Brush.Color:=clWhite; //clWindow funktioniert hier nicht!!!

if Item.subitems[subitem-1]='' then
    Sender.Canvas.Brush.Color:=$00AAEEFF
    else
      if strtoint(Item.subitems[subitem-1])<5 then
       Sender.Canvas.Font.color:=clWindowText
      else
       Sender.Canvas.Font.color:=clred;

end;


JVS
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 04.11.09 10:21 
Hallo,

wenn aber jemand eine andere System-Farbe für Fenster einstellt, bleibt clWhite :wink:

Da scheint mir Delphi etwas vergessen zu haben, die Systemfarbe clWindows wird wohl an der Stelle nicht richtig umgesetzt.
clWhite = 16777215
clWindow = -16777211
Dort hat user profile iconLossy eX mal etwas zu clWindow geschrieben: Link

Das funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.meinLVCustomDrawSubItem(Sender: TCustomListView;
         Item: TListItem; SubItem: Integer; State: TCustomDrawState;  var DefaultDraw: Boolean);
begin  
  if Item.subitems[subitem-1]<>'' then
    Sender.Canvas.Brush.Color := ColorToRGB(clWindow)
    else    
      Sender.Canvas.Brush.Color := $00AAEEFF;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )