Delphi: draw own progress bar in List View

后端 未结 3 497
余生分开走
余生分开走 2020-12-07 19:43

I have a list view and draw it with OwnerDraw.

How to draw a simple and smooth progress bar with rounded angles and a line on the top a

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 19:58

    Font will be incorrect for additional sub-items.

    Sender.Canvas.Font.OnChange(Sender);

    Thanks to Delphi TListview OwnerDraw SubItems - change default font (it's bold somehow after you Draw on the canvas)

    e.g.:

    procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    var
      ListView: TListView absolute Sender;
      R: TRect;
    begin
      DefaultDraw := SubItem <> StatusColumnIndex;
      if not DefaultDraw then
      begin
        ListView_GetSubItemRect(ListView.Handle, Item.Index, SubItem,
          LVIR_BOUNDS, @R);
        DrawStatus(ListView.Canvas.Handle, R, State, ListView.Font, 'Downloading',
          Random(101) / 100);
      end;
    Sender.Canvas.Font.OnChange(Sender);
    end;
    

提交回复
热议问题