TFormOnPaint (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following code loads a background bitmap onto the Canvas of the main form in the OnPaint event handler.


Code

#include <memory>       //For STL auto_ptr class

Graphics::TBitmap *TheGraphic;

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

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  static std::auto_ptr<Graphics::TBitmap> _TheGraphicCleaner(TheGraphic = new Graphics::TBitmap());  // Create the bitmap object.
  TheGraphic->LoadFromFile("..\\bigf.bmp"); // Load the bitmap from a file.
}

Uses