Autor Beitrag
JensLaskowski
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 168

Win XP
BDS 2006 Architect
BeitragVerfasst: Do 05.07.07 15:19 
Hallo,

ich suche eine procedure, mit der man jeden zweiten Listboxeintrag farbig hinterlegen kann.

Also z.B.: Die Standardfarbe ist weiß. Alle Einträge mit einer gerade ItemIndex sollen aber schwarz hinterlegt sein.

Hat jemand so eine Procedure?? Oder gibt es eine ander Möglichkeit??

Mit freundlichen Grüßen
JensLaskowski

_________________
Nichtstun macht nur dann Spaß, wenn man eigentlich viel zu tun hätte.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 05.07.07 15:31 
Moin!

Suche in: Delphi-Library, Delphi-Forum LISTBOX ZEBRA

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
JensLaskowski Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 168

Win XP
BDS 2006 Architect
BeitragVerfasst: Do 05.07.07 15:36 
Danke.

Wenn ich den Code richtig vertsanden habe, ist das dieser???

ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
procedure DrawListBoxZCB(Control: TWinControl; Index: Integer; Rect: TRect;
  State: TOwnerDrawState);
const
  Col1: array [Boolean] of TColor = ($00F8F8F8, clWindow);
  Col2: array [Boolean] of TColor = (clInactiveCaptionText, clWindowText);
var
  Bmp: TBitmap;
  TopDif: Integer; // Gleicht die Höhendifferenz aus
begin
  Bmp := TBitmap.Create;
  try 
    with (Control as TListbox) do 
    begin
      Bmp.Transparent := True;
      { Hier Bitmap von Festplatte laden }
      { Beispiel }
      //Bmp.LoadFromFile('c:\Bmp16.bmp');
      { Hier Bitmap aus Ressorce laden }
      { Beispiel }
      //Bmp.LoadFromResourceName(HInstance,'Bitmap1');
      { Hier Bitmap aus ImageList laden}
      { Beispiel mit ImageList1 auf Formular Form1 }
      //with Form1 do ImageList1.GetBitmap(0, Bmp);
      if odSelected in State then 
        Canvas.Font.Color := clCaptionText 
      else
      begin
        Canvas.Brush.Color := Col1[Odd(Index)];
        Canvas.Font.Color := Col2[(Control as TListbox).Enabled];
      end;

      TopDif := (ItemHeight div 2) - (Canvas.TextHeight(#32) div 2);
      Canvas.TextRect(Rect, Rect.Left + Bmp.Width + 1, Rect.Top + TopDif, Items[Index]);
      Canvas.Draw(Rect.Left, Rect.Top, Bmp);
    end;
  finally 
    Bmp.Free; 
  end;
end; {Popov}


hab leider immoment kein Delphi da und kann es nicht selber ausprobieren.

Mit freundlichen Grüßen
JensLaskowski

_________________
Nichtstun macht nur dann Spaß, wenn man eigentlich viel zu tun hätte.
JensLaskowski Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 168

Win XP
BDS 2006 Architect
BeitragVerfasst: Fr 06.07.07 15:08 
Also ich hab den Code jetzt ausprobiert und es hat funktioniert.

Mit freundlichen Grüßen
JensLaskowski

_________________
Nichtstun macht nur dann Spaß, wenn man eigentlich viel zu tun hätte.