form1是主窗体,运行时自动创建;
form2是在Project->Option->Forms中设置为可使用的窗体;
如何使用form1上的Button1按钮,使得form2创建,然后定时5秒钟后自动关闭?
尝试了在Button1的点击事件中使用
form2.create();但是不知道括号中该使用什么参数。
Timer1放置在form1上,定时5秒后,触发事件中使用了form2.close;或者在五秒钟内点击form2上的Button2,关闭窗口(只是设想,没有测试,因为form2在调试中始终没有出现过)。我的目的是在Button1点击后能弹出一个窗口,提示用户等待5秒钟,就像在windows中常见的那种左边带有沙漏,或者窗口上带有进度条那样的。不知道有没有更简便的方法可以使用。谢谢。
form2是在Project->Option->Forms中设置为可使用的窗体;
如何使用form1上的Button1按钮,使得form2创建,然后定时5秒钟后自动关闭?
尝试了在Button1的点击事件中使用
form2.create();但是不知道括号中该使用什么参数。
Timer1放置在form1上,定时5秒后,触发事件中使用了form2.close;或者在五秒钟内点击form2上的Button2,关闭窗口(只是设想,没有测试,因为form2在调试中始终没有出现过)。我的目的是在Button1点击后能弹出一个窗口,提示用户等待5秒钟,就像在windows中常见的那种左边带有沙漏,或者窗口上带有进度条那样的。不知道有没有更简便的方法可以使用。谢谢。
var
i:Integer;
begin
with Form1 do
begin
Show;
For i:=1 to 1000 do
begin
Gauge1.Progress:=Gauge1.Progress+1;
end;
Close;
end;
end;
Var
Form2 : TForm ;
Begin
Form2 := TForm.Create(nil);
Form2.Width ...
Form2.Top...
Form2.Left...
Form2.Height ... Form2.Show;
.....
Sleep(5000);
Form2.Hide ;
Form2.Free ;
.......
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses unit2;
{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.enabled:=true;
form2.showmodal;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
form2.ProgressBar1.StepIt ;
if form2.ProgressBar1.Position=5 then
begin
form2.Close ;
timer1.Enabled :=false;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
timer1.Enabled :=false;
end;end.unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;type
TForm2 = class(TForm)
ProgressBar1: TProgressBar;
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.FormActivate(Sender: TObject);
begin
with progressbar1 do
begin
min:=0;
max:=5;
step:=1;
smooth:=true;
end;
end;end.