RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomActiveForm.OnPaint Event

Occurs when the form is redrawn.

Pascal
property OnPaint: TNotifyEvent;
C++
__property TNotifyEvent OnPaint;

Use OnPaint to perform special processing when the form is redrawn. Any special painting on the form should be done in this event. OnPaint occurs before any controls on the form are painted. 

To determine which portions of the form's canvas need to be repainted, use the ClipRect property of the canvas. 

If you use the form's Canvas property outside the OnPaint event, it will be erased and drawn-over by the next OnPaint event.  

C++ Examples: 

 

/*
The following code loads a background bitmap onto the Canvas
of the main form in the OnPaint event handler.
*/
Graphics::TBitmap *TheGraphic;

void __fastcall TForm1::FormPaint(TObject *Sender)// OnPaint event handler
{
  Form1->Canvas->Draw(0, 0, TheGraphic); // Draw the graphic on the Canvas
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TheGraphic = new Graphics::TBitmap(); // Create the bitmap object
  TheGraphic->LoadFromFile("..\\bigf.bmp"); // Load the bitmap from a file
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  delete TheGraphic;
}

 

Delphi Examples: 

{
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;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!