在 Delphi 中以编程方式启动屏幕

发布于 2024-09-11 21:35:33 字数 1431 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷情 2024-09-18 21:35:33

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

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

这是我的启动表单中的代码:

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 中:

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;

在您的项目文件中,做这样的事情:(

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.

大部分代码都是我凭空写出来的,它可能无法立即编译)

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)

冧九 2024-09-18 21:35:33

闪屏在技术上没有什么困难,它只是一个弹出然后消失的表单。因此,在 Delphi 中实现启动屏幕的最佳方法是:让图形设计师为您绘制一个!

There's nothing technically difficult about the splash screen, it's just a form that pops up and then goes away. So the best way to implement a splash screen in Delphi is: Get a graphics designer to draw one for you!

勿挽旧人 2024-09-18 21:35:33

我是这样做的:首先通过向项目添加一个空表单来创建一个新单元(文件->新建->表单),让我们将该单元称为splashy,将其(表单)边框样式设置为bsnone并将其设置为将属性命名为“splashscreen”或您想要的任何内容,首先使用 mspaint 或其他东西设计图片,然后将 timage 组件放在表单上并通过它打开图像文件,然后添加行:“splashscreen:Tsplashscreen;”来设计它(表单)。 (agian,你可以将其命名为任何你想要的)'到units var部分,然后将此单位的名称添加到第一个单位的uses子句中
下面的代码构成了 oncreate 事件的第一个单元:

  procedure TForm1.FormCreate(Sender: TObject);
    var
     splash :  Tsplashscreen;
   begin
     Splash := TSplashScreen.Create(Application);
     Splash.Show;
    Sleep(1000); //as long as you want screen to be displayed 1000 = 1 second
     Splash.Hide;
     Splash.Free;
    end;

this is how i do it: first create a new unit by adding an empty form to your project(file->new->form),lets call this unit splashy, set its(form's) border style to bsnone and set its name property to 'splashscreen' or what ever you desire, design it(form) by first designing a picture using mspaint or some thing then dropping a timage component on form and openening the image file through it ,add line: 'splashscreen: Tsplashscreen;(agian you can name it what ever you want)' to units var section then add this unit's name to to first unit's uses clause
and the code below to first units form oncreate event:

  procedure TForm1.FormCreate(Sender: TObject);
    var
     splash :  Tsplashscreen;
   begin
     Splash := TSplashScreen.Create(Application);
     Splash.Show;
    Sleep(1000); //as long as you want screen to be displayed 1000 = 1 second
     Splash.Hide;
     Splash.Free;
    end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文