unit TFormOnPaint;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, StdCtrls, ToolWin, DBCtrls, ImgList;

type
  TForm1 = class(TForm)
    DBText1: TDBText;
    Label1: TLabel;
    Image1: TImage;
    PaintBox1: TPaintBox;
    Splitter1: TSplitter;
    ToolBar1: TToolBar;
    ListBox1: TListBox;
    StatusBar1: TStatusBar;
    ComboBox1: TComboBox;
    ListView1: TListView;
    PageControl1: TPageControl;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  TheGraphic: TBitmap; { Add this declaration for the graphic}

implementation

{$R *.dfm}

// BeginExample: TFormOnPaint
// Event: Forms.TCustomForm.OnPaint

// BeginCode
{
The following code loads a background bitmap onto the Canvas
of the main form in the OnPaint event handler.
}
procedure TForm1.FormPaint(Sender: TObject); { OnPaint event handler}
begin
  Form1.Canvas.Draw(0, 0, TheGraphic); { Draw the graphic on the Canvas }
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  TheGraphic := TBitmap.Create; { Create the bitmap object }
  TheGraphic.LoadFromFile('bigf.bmp'); { Load the bitmap from a file}
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  (TheGraphic as TObject).Free;
end;
// EndCode
// EndExample: TFormOnPaint
end.
