我使用这里提到的方法创建了我的启动画面:http://delphi.about.com/od/formsdialogs/a/splashscreen.htm如何显示此启动画面3秒?
我需要在显示主窗体前显示启动画面3秒。
请帮忙。谢谢。
我使用这里提到的方法创建了我的启动画面:http://delphi.about.com/od/formsdialogs/a/splashscreen.htm如何显示此启动画面3秒?
我需要在显示主窗体前显示启动画面3秒。
请帮忙。谢谢。
项目文件内:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
uSplashScreen in 'uSplashScreen.pas' {frmSplashScreen};
{$R *.res}
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
frmSplashScreen := TfrmSplashScreen.Create(nil);
try
frmSplashScreen.Show;
// Create your application forms here
Application.CreateForm(TForm1, Form1);
while not frmSplashScreen.Completed do
Application.ProcessMessages;
frmSplashScreen.Hide;
finally
frmSplashScreen.Free;
end;
Application.Run;
end.
内闪屏单元:
unit uSplashScreen;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TfrmSplashScreen = class(TForm)
Timer1: TTimer;
procedure FormShow(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
Completed: Boolean;
end;
var
frmSplashScreen: TfrmSplashScreen;
implementation
{$R *.dfm}
procedure TfrmSplashScreen.FormShow(Sender: TObject);
begin
OnShow := nil;
Completed := False;
Timer1.Interval := 3000; // 3s minimum time to show splash screen
Timer1.Enabled := True;
end;
procedure TfrmSplashScreen.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
Completed := True;
end;
end.
启动屏幕将是3秒以上的最短时间,如果它需要更多的时间来创建应用程序的所有形式可见。
您应该使用定时器,其间隔设置为3000(3(s)* 1000(ms))。启用必须设置为true。在定时器的默认事件上添加代码,这是为了显示主窗体。
为了达到你想要的效果,你可以按照你提供的链接中描述的方法,在启动画面的表单代码中放入一个定时器,它在3秒后被触发并关闭表单。
主要.dpr文件
var SplashScreen : TForm2;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
SplashScreen := TForm2.Create(nil); // Creating with nil so this is not registered as main form
try
SplashScreen.ShowModal; // Blocking the execution for as long as this form is open
finally
SplashScreen .Free;
end;
Application.CreateForm(TForm1, Form1);
Application.Run;
将在其上的 '启动画面' 添加定时器的形式,在3000间隔启用(3S)
与下列事件处理程序
procedure TForm2.Timer1Timer(Sender: TObject);
begin
Self.Close;
end;
SplashScreen是MainForm,所以当你关闭飞溅时,整个应用程序将关闭(关闭主窗体将关闭应用程序)。我错了吗? – Ampere 2017-08-10 09:52:11
frmSplashScreen是MainForm,所以当你释放飞溅时,整个应用程序将关闭(关闭主窗体将关闭应用程序)。我错了吗? – Ampere 2017-08-10 09:50:59