主 题: 一个土特产的进度条~
作 者: Stack (公冶长)
新建一个工程
1 // 把下面字符串拷贝到窗体上(在IDE的窗体设计中拷贝)
object pbProgress: TDrawGrid
Left = 76
Top = 32
Width = 301
Height = 25
Color = clInfoBk
ColCount = 100
Ctl3D = False
DefaultColWidth = 2
DefaultRowHeight = 30
Enabled = False
FixedCols = 0
RowCount = 1
FixedRows = 0
ParentCtl3D = False
ScrollBars = ssNone
TabOrder = 0
end
2 增加如下变量
fProgress: Integer;
fRandomColor: integer;
3 放置一个Timer控件, 时间间隔设成100ms好了
procedure TForm1.FormCreate(Sender: TObject);
begin
fProgress := 0;
Randomize();
fRandomColor := Random(255);
end;
// pbProgress的DrawCell事件
procedure TForm1.pbProgressDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
pbProgress.Canvas.Brush.Color := RGB(aCol * 255 div 100, (100 - aCol) * 255 div 100, fRandomColor);
if aCol <= fProgress then
pbProgress.Canvas.FillRect(Rect);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
fProgress := fProgress + 1;
pbProgress.Repaint;
Application.ProcessMessages;
end;
几下就弄出一个进度条, 有兴趣的TryTry