Einzelnen Beitrag anzeigen

100nF

Registriert seit: 7. Nov 2004
639 Beiträge
 
#15

Re: Lösung TListview eigene Farbe andere Icons für Aktive It

  Alt 4. Dez 2005, 17:25
also ich habe alles im oncustomdrawitem, hier der code:
Delphi-Quellcode:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  aTextRect, aIconRect:TRect; subitem: integer;
begin
  if (Item.Index=TListView(Sender).ItemIndex) or (TListView(Sender).ItemFocused=Item) or (Item.selected) then
  begin
    DefaultDraw:=false;

    aIconRect:=Item.DisplayRect(drBounds);
    aTextRect:=Item.DisplayRect(drLabel);

    with Sender do
    begin
      Canvas.Pen.Color := $00CDEFE9;
      Canvas.Brush.Color := $00CDEFE9;
      Canvas.Rectangle(aTextRect);

      aTextRect.Left:=aTextRect.Left+2;
      Windows.DrawText(Canvas.Handle, @Item.Caption[1], Length(Item.Caption),
                         aTextRect, DT_VCENTER);

      Canvas.Brush.Color:=$008FC2B3;
      Canvas.FrameRect(aTextRect);

      TListView(Sender).SmallImages.Draw(Canvas,aIconRect.Left+2
                         ,aIconRect.Top,1);

      for SubItem:=1 to Item.SubItems.Count do
      begin
        ListView_GetSubItemRect(Sender.Handle, Item.Index, SubItem, LVIR_BOUNDS, @aTextRect);

        if TListView(Sender).ViewStyle=vsReport then
        begin
          with Sender do
          begin
            Canvas.Pen.Color := $00CDEFE9;
            Canvas.Brush.Color := $00CDEFE9;
            aTextRect.Left:=aTextRect.Left+2;
            Canvas.Rectangle(aTextRect);

            Windows.DrawText(Canvas.Handle, @Item.SubItems[SubItem-1][1], Length(Item.SubItems[SubItem-1]), aTextRect, DT_VCENTER);

            Canvas.Brush.Color:=$008FC2B3;
            Canvas.FrameRect(aTextRect);
          end;
        end;
      end;
    end;
  end;
end;
  Mit Zitat antworten Zitat