AI摘要

本文介绍了如何在Delphi中的ListView控件上为每个列表项添加进度条。首先,在FormShow事件中为每个列表项创建一个进度条,并设置其位置和样式。然后,在FormDestroy事件中释放这些进度条。最后,通过Timer控件定时更新进度条的进度。文章还提供了一个示例图片和源代码下载链接。
本文介绍了如何

procedure TMainForm.FormShow(Sender: TObject);
var
  I: Integer;
  ProBar: TGauge;
  Li: TListItem;
begin
  for I := 0 to DataListView.Items.Count - 1 do begin
      Li := DataListView.Items[I];
      ProBar := TGauge.Create(Self);
      ProBar.Parent := DataListView;
      Li.Data := ProBar;
      ProBar.Left := Li.DisplayRect(drBounds).Left + DataListView.Columns[0].Width+5;
      ProBar.Top := Li.DisplayRect(drBounds).Top+1;
      ProBar.Width := DataListView.Columns[1].Width-5;
      ProBar.Height:= 14;
      ProBar.BackColor:=$00F6F6F6;
      ProBar.ForeColor:=clSilver;
      ProBar.Font.Name:='Tahoma';
      ProBar.Font.Size:=8;
  end;
end;

procedure TMainForm.FormDestroy(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to DataListView.Items.Count - 1 do begin
      if DataListView.Items[I].Data <> nil then
        TProgressBar(DataListView.Items[I].Data).Free;
  end;
end;

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
  Randomize;
  TGauge(DataListView.Items[Random(DataListView.Items.Count)].Data).Progress := Random(101);
end;


listview.jpg

listviewprogressbar.rar

※相关文章推荐※



最后修改:2009 年 08 月 16 日
点赞的人是最酷的