In many applications, after the startup program, there is a picture that is generally image-based, the text is a screen, which is usually used to display software or company's topic logo, software name, author, copyright and version. Information, etc., leave few seconds or pressing any button to enter the dominant interface, this picture is called the SPLASH screen, which means the eye-catching screen. Another use of this picture is to show a beautiful, comfortable image when processing the time-consuming process.
In fact, this skill can be easily achieved in Delphi. Here is an example to gradually explain how to implement the SPLASH screen.
1 In your program adds a form, change its name to splashform, BorderStyle property is set to bsnone, and the position property is set to POSCREENCENTER.
2 Add a range of necessary components for the Splashform form, such as Label, Panel, Image, Shape, and Bevel.
3 Using the Project | Option function item to move the SplashForm form from the Auto-Create table to the Available table.
4 Add the Unit of the SplashForm form to the homeform of the main form Unit.
5 Add a control code in the main program. DPR file, the location is after Begin, before the other code, the code is as follows:
Splashform: = Tsplashform.create (Application);
Splashform.show;
Splashform.refresh;
Its purpose is to establish and display the SPLASH form before establishing other forms and running procedures.
6 Write the response process of the main form onshow event.
Splashform.free;
In this example, this code acts to release the SPLASH form when the screen is displayed.
7 Finally, write a delay program for the main program. The purpose is to make the SPLASH screen have a period of stay on the screen. The easiest way to use an invalid loop, such as:
Var i, x: longint
For i: = 1 to 100000 do
x: = i;
However, due to the difference in machine operation, there is a slow, the performance is not ideal, the best way is to use the time function, pre-specify the SPLASH screen's residence time. The following code allows the splash screen to stay on the screen for 5 seconds.
VAR Time1: TDATETIME;
Time1: = now;
Repeat
Until Time1 Strtotime ('00: 00: 5 ') <= NOW;
Of course, the time delay code must be displayed after the Splash screen display, the specific location is before the SplashForm.Refresh; the program main form is established.
Readers can use the above methods to add a splash screen in your application to make your program more beautiful.
The following is the program source code. Where splash form borrows Delphi / Demos / DB / MastApp / Splash.
{Project1.dpr}
PROGRAM Project1;
Uses
Forms, sysutils,
Unit1 in 'unit1.pas' {form1},
Splash in '../../demos/db/mastapp/splash.pas' {splashform};
{R * .res}
VAR Time1: TDATETIME;
Begin
Splashform: = Tsplashform.create (Application);
Splashform.show;
Splashform.refresh;
Time1: = now;
Repeat
Until Time1 Strtotime ('00: 00: 5 ') <= now; application.initialize;
Application.createform (TFORM1, FORM1);
Application.run;
End.
{Unit1.PAS main form}
Unit unit1;
Interface
Uses
Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms,
Dialogs, Splash;
Type
TFORM1 = Class (TFORM)
Procedure FormShow (Sender: TOBJECT);
Private
{Private Declarations}
public
{Public declarations}
END;
VAR
FORM1: TFORM1;
IMPLEMENTATION
{R * .dfm}
Procedure TFORM1.FORMSHOW (Sender: TOBJECT);
Begin
Splashform.free;
END;
End.
{Splash.Pas Splash Forms}
Unit Splash;
Interface
Uses
SYSUTILS, Windows, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Stdctrls, ExtCtrls;
Type
Tsplashform = Class (TFORM)
Panel1: TPANEL;
Label3: TLABEL;
Bevel1: TBevel;
Label1: TLABEL;
Image1: timage;
END;
VAR
Splashform: Tsplashform;
IMPLEMENTATION
{R * .dfm}
End.