(page requirements)
Downloads

Windows, web pages, multimedia programs, all have backgrounds. How come your Delphi form doesn't?

Of course you could place a "TImage" component on your form and set its "Alignment" to "Client" in order to place a background image on your form. Here's another way:
  1. Add following code to your form's "Public declarations" section:
     
    bmpBackground : TBitmap;
    Listing #1 : Delphi code. Download code (0.15 KB).
     
  2. Double click on your form and add bitmap initialization code in the "FormCreate" event:
     
    bmpBackground := TBitmap.Create;
    bmpBackground.
      LoadFromFile( 'c:windowssetup.bmp' );
    Listing #2 : Delphi code. Download code2 (0.21 KB).
     
  3. Go to the form's events list and double click on "OnPaint". Add following line to the "FormPaint" event:
     
    Canvas.Draw( 0, 0, bmpBackground );
    Listing #3 : Delphi code. Download code3 (0.16 KB).
     
  4. Finally insert the following code in to the "FormDestroy" event ("OnDestroy" event):
     
    bmpBackground.Free;
    Listing #4 : Delphi code. Download code4 (0.15 KB).
     
 
Sample screen shot:
 
 
 
Applicable Keywords : Delphi, Delphi 1.x, Delphi 2.x, Delphi 3.x, Source Code
 
 
 
Copyright © 2009 Chami.com. All Rights Reserved. | Advertise | Created in HTML Kit editor