2.//编写状态栏的自绘代码 procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;Panel: TStatusPanel;const Rect: TRect); begin //注意这里的Panels[1]指的就是第2块面板,因为默认是从0开始的 if Panel = StatusBar.Panels[1] then with ProgressBar1 do begin Top := Rect.Top; Left := Rect.Left; Width := Rect.Right - Rect.Left - 15; Height := Rect.Bottom - Rect.Top; end; end; 关键问题解决之后,我们来一个小例子,这样就可以有一个全局的印象了,控件的摆放如(图3)所示,编写代码如下:
procedure TForm1.Button1Click(Sender: TObject); var i : integer; begin ProgressBar1.Position := 0; ProgressBar1.Max := 100;
for i := 0 to 100 do begin ProgressBar1.Position := i; Sleep(25); end; end; 运行一下这个小程序,点击一下按钮,看到了吧,进程条在状态栏中动起来了。