在Delphi中以编程方式启动屏幕 [英] Splash Screen Programmatically in Delphi
问题描述
在Delphi中实现初始屏幕的最佳方法是什么?
What is the best way to implement splash screen in Delphi?
推荐答案
创建表单,使其为 FormStyle
= fsStayOnTop
,将其边框样式设置为none,将其标题设置为空白。这将创建一个顶部没有标题栏的表单。在表单上放置 TImage
并将位图加载到其中。
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.
在表单上拖放一个TTimer(这将
Drop a TTimer on the form (this will be used to make sure the splash screen stays up for at least some period.
以下是我在初始表单中使用的代码: p>
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;
在FormCreate中:
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中以编程方式启动屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!