在Delphi中编程的Splash屏幕 [英] Splash Screen Programatically in Delphi

查看:127
本文介绍了在Delphi中编程的Splash屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

创建一个表单,使其成为 FormStyle = fsStayOnTop ,将其边框样式设置为none,并将其标题设置为空白。这将创建一个没有顶部标题栏的表单。在表单上放一个 TImage ,并加载你的位图。



在表单上放一个TTimer(这将用于确保启动屏幕至少保持至少



这是我的飞溅形式中的代码: p>

  TSplashForm = class(TForm)
Image1:TImage;
CloseTimer:TTimer;
procedure CloseTimerTimer (Sender:TObject);
procedure FormCreate(Sender:TObject);
procedure FormClose(Sender:TObject; var Action:TCloseAction);
procedure FormDestroy(Sender:TObject);
private
FStartTicks:integer;
FOKToClose:boolean;
public
属性OKToClose:boolean read FOKToClose write FOKToClose;
end;

var
SplashForm:TSplashForm;

在FormCreate中:

  procedure TSplashForm.FormCreate(Sender:TObject); 
begin
FStartTicks:= GetTickCount;
end;

亲cedure TSplashForm.CloseTimerTimer(Sender:TObject);
const
CTimeout = 3000;
begin
if(GetTickCount - FStartTicks> CTimeout)和OKToClose然后
关闭;
结束

procedure TSplashForm.FormClose(Sender:TObject; var Action:TCloseAction);
begin
动作:= caFree;
结束

程序TSplashForm.FormDestroy(发件人:TObject);
begin
SplashForm:= nil;
结束

在项目文件中,执行以下操作:

  begin 

SplashForm:= TSplashForm.Create(nil)

Application.Initialize;
Application.Title:='我的程序';

//创建表单,初始化数据库连接等
Application.CreateForm(TForm1,Form1);

如果分配(SplashForm)然后
SplashForm.OkToClose:= True;

Application.Run;

结束。

(这段代码大部分都是从我头上写下来的,可能不会在蝙蝠)


What is the best way to implement splash screen in Delphi?

解决方案

Create a form, make it's FormStyle = fsStayOnTop, set it's border style to none and it's caption to blank. This will create a form that doesn't have a caption bar at the top. Drop a TImage on the form and load your bitmap into it.

Drop a TTimer on the form (this will be used to make sure the splash screen stays up for at least some period.

Here's the code I have in my splash form:

TSplashForm = class (TForm)
  Image1: TImage;
  CloseTimer: TTimer;
  procedure CloseTimerTimer(Sender: TObject);
  procedure FormCreate(Sender: TObject);
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure FormDestroy(Sender: TObject);
private
  FStartTicks: integer;
  FOKToClose: boolean;
public
  property OKToClose: boolean read FOKToClose write FOKToClose;
end;

var
  SplashForm: TSplashForm;

In the FormCreate:

procedure TSplashForm.FormCreate(Sender: TObject);
begin
  FStartTicks := GetTickCount;
end;

procedure TSplashForm.CloseTimerTimer(Sender: TObject);
const
  CTimeout = 3000;
begin
  if (GetTickCount - FStartTicks > CTimeout) and OKToClose then
    Close;
end;

procedure TSplashForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TSplashForm.FormDestroy(Sender: TObject);
begin
  SplashForm := nil;
end;

In your project file, do something like this:

begin

  SplashForm := TSplashForm.Create(nil)

  Application.Initialize;
  Application.Title := 'My Program';

  //create your forms, initialise database connections etc here
  Application.CreateForm(TForm1, Form1);

  if Assigned(SplashForm) then
    SplashForm.OkToClose := True;

  Application.Run;

end.

(most of this code was written off the top of my head, it might not compile right off the bat)

这篇关于在Delphi中编程的Splash屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆