Entwickler-Ecke

Grafische Benutzeroberflächen (VCL & FireMonkey) - Zebrastreifenlook in TListview / Report


delphimike - Mi 19.01.05 15:29
Titel: Zebrastreifenlook in TListview / Report
Wie kann ich jede 2. Zeile in einem TListview (Modus report) anders einfärben.
Zebrastreifenlook zur besseren Lesbarkeit


Spaceguide - Mi 19.01.05 17:08

Als erstes fällt mir ein: OnDrawItem mit eigener Routine überschreiben.


toms - Mi 19.01.05 17:17

Spaceguide hat folgendes geschrieben:
Als erstes fällt mir ein: OnDrawItem mit eigener Routine überschreiben.


Ein Beispiel findest du hier:
http://www.swissdelphicenter.ch/de/showcode.php?id=818


matze.de - Mi 19.01.05 18:13

versuch mal das hier :)


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.DrawListBoxZC(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
const
  Col1: array[Boolean] of TColor = ($00C7C7C7$00C7C7C7); //Farbe für Col1
  Col2: array[Boolean] of TColor = (clBlack, clBlack);  //Farbe für Col2
var
  TopDif: Integer;
begin
  with (Control as TListBox) do
  begin
    if odSelected in State then
    begin
      Canvas.Brush.Style := bsClear;
      Canvas.Font.Color := clCaptionText;
    end
    else
    begin
      Canvas.Brush.Color := Col1[Odd(Index)];
      Canvas.Font.Color := Col2[(Control as TListBox).Enabled];
    end;
    TopDif := (ItemHeight div 2) - (Canvas.TextHeight(#32div 2);
    Canvas.TextRect(Rect, Rect.Left, Rect.Top + TopDif, Items[Index]);
  end;
end;


aufruf geht so:

Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.ApplicationListDrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  DrawListBoxZC(Control, Index, Rect, State);
end;


mfg matze