Screen saver in Delphi

What is the best way to implement a screensaver in Delphi?

+7
delphi
source share
3 answers

Create a form, make it FormStyle = fsStayOnTop , set the border style to none and the title will be empty. This will create a form that does not have a top title bar. Drop a TImage in the form and load a bitmap into it.

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

Here is the code that 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 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 the project file, do the following:

 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 has been written off from my head, it cannot be compiled right away)

+7
source share

There is nothing technically complicated in a splash screen; it is just a form that appears and then leaves. So the best way to implement a screensaver in Delphi is to get a graphic designer to draw it for you!

+1
source share

here's how I do it: first create a new block by adding an empty form to your project (file-> new-> form), let this device splashy, set the frame (form) style to bsnone and set its name, property โ€œsplashscreenโ€ or whatever you want, design it (form) by first creating an image using mspaint or some thing, then discarding the time component in the form and opening the image file through it, add the line: "splashscreen: Tsplashscreen; (agian you can call its what ever you want) in the var unit, then add this name for the first sentence I use units and the code below for the first units generates an 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; 
+1
source share

All Articles