delphi 实现程序放放多个进程条  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 实现程序放放多个进程条


delphi 实现程序放放多个进程条

很不错的一个 方法,可以同时实现两个同时进行 ! 呵呵 看代码

Delphi 中TStatusbar上通常不允许放其它组件。但是经常有需求要在右下角的状态栏上放置进程条以达到更好的显示效果,下面介绍如何将多个进程条组件添加到一个状态栏 TStatusbar上,以及如何适应状态栏的大小来调整进程条的大小。

//状态栏可以自定义为多个panel,我们首先要取得放进程条在那个panel的尺寸大小
//以下函数需要引用 单元 commctrl
//第二个参数中 0是取得状态栏第一个panel 依次 1为取得第二个panel
Statusbar1.Perform(SB_GETRECT, 0, Integer(@R));
Statusbar1.Perform(SB_GETRECT, 2, Integer(@R2));
//我们设定在状态栏放两个进程条,分别放在第一个与第三个panel中,当然状态栏你要先设好为三个

//设置进程控件的parent为状态栏,即可将进程条放在状态栏上
progressbar1.Parent := Statusbar1;
progressbar2.Parent := Statusbar1;

//设置第一个进程条在状态栏第一个panel的位置
progressbar1.Top := r.Top; //set size of
progressbar1.Left := r.Left; //Progressbar to
progressbar1.Width := r.Right – r.Left; //fit with panel
progressbar1.Height := r.Bottom – r.Top;

//设置第二个进程条在状态栏第三个个panel的位置
progressbar2.Top := r2.Top; //set size of
progressbar2.Left := r2.Left; //Progressbar to
progressbar2.Width := r2.Right – r2.Left; //fit with panel
progressbar2.Height := r2.Bottom – r2.Top;
//以上我们设定进程条充满各自的panel,当然你可以设定进程条的top,left等属性来调整显示位置

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,commctrl, ComCtrls, StdCtrls;

type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
ProgressBar1: TProgressBar;
ProgressBar2: TProgressBar;
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
r,r2: TRect;
begin
//状态栏可以自定义为多个panel,我们首先要取得放进程条在那个panel的尺寸大小
//以下函数需要引用 单元 commctrl
//第二个参数中 0是取得状态栏第一个panel 依次 1为取得第二个panel
Statusbar1.Perform(SB_GETRECT, 0, Integer(@R));
Statusbar1.Perform(SB_GETRECT, 2, Integer(@R2));
//我们设定在状态栏放两个进程条,分别放在第一个与第三个panel中,当然状态栏你要先设好为三个

//设置进程控件的parent为状态栏,即可将进程条放在状态栏上
progressbar1.Parent := Statusbar1;
progressbar2.Parent := Statusbar1;

//设置第一个进程条在状态栏第一个panel的位置
progressbar1.Top := r.Top; //set size of
progressbar1.Left := r.Left; //Progressbar to
progressbar1.Width := r.Right - r.Left; //fit with panel
progressbar1.Height := r.Bottom - r.Top;

//设置第二个进程条在状态栏第三个个panel的位置
progressbar2.Top := r2.Top; //set size of
progressbar2.Left := r2.Left; //Progressbar to
progressbar2.Width := r2.Right - r2.Left; //fit with panel
progressbar2.Height := r2.Bottom - r2.Top;
//以上我们设定进程条充满各自的panel,当然你可以设定进程条的top,left等属性来调整显示位置
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to 100 do
begin
Sleep(100);
ProgressBar1.Position:=i;
ProgressBar2.Position:=i;
end;
end;

end.

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.046860933303833 seconds