如何在3秒内显示此启动画面?

时间:2010-07-31 14:51:25

标签: delphi delphi-2010

我使用此处提到的方法创建了启动画面:http://delphi.about.com/od/formsdialogs/a/splashscreen.htm

我需要在显示主窗体之前显示启动画面3秒钟。

请帮忙。感谢。

3 个答案:

答案 0 :(得分:6)

项目内部文件:

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秒或更长时间。

答案 1 :(得分:3)

要实现您想要的效果,您可以按照您提供的链接中描述的方法,并在启动屏幕的表单代码中放置一个计时器,该计时器在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;

答案 2 :(得分:1)

您应该使用计时器,其间隔设置为3000(3(s)* 1000(ms))。必须将Enabled设置为true。在Timer's-default-event上添加代码,用于显示主窗体。