Delphi Listview中批量显示带百分比进度条示例源码及演示效果

本文展示了一个使用Delphi创建动态进度条的例子。通过在ListView中添加TGauge组件,实现了多个进度条随时间更新的效果。该示例还包含了定时器控制进度更新的实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.ExtCtrls, Vcl.ComCtrls, Samples.Gauges;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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

end;

procedure TForm1.FormShow(Sender: TObject);
var
  I: Integer;
  ProBar: TGauge;
  Li: TListItem;
begin
  for I := 0 to ListView1.Items.Count - 1 do
  begin
    Li := ListView1.Items[I];
    ProBar := TGauge.Create(Self);
    ProBar.Parent := ListView1;
    Li.Data := ProBar;
    ProBar.Left := Li.DisplayRect(drBounds).Left + ListView1.Columns[0].Width + 5;
    ProBar.Top := Li.DisplayRect(drBounds).Top + 1;
    ProBar.Width := ListView1.Columns[1].Width - 5;
    ProBar.Height := 14;

    //ProBar.BackColor:=$00F6F6F6;
    //ProBar.ForeColor:=clSilver;
    ProBar.BackColor := $00F6F6F6;
    ProBar.ForeColor := clblue;

    ProBar.Font.Name := 'Tahoma';
    ProBar.Font.Size := 8;

  end;

end;

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

end.

效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值