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.
效果: