//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//create
an off-screen Bitmap
MyBitmap = new Graphics::TBitmap();
}
//--------------------------------------------------------------------------------
//Draw on the offscreen Bitmap and blit it to the PaintBox
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//adjust
the dimensions
MyBitmap->Width
= PaintBox1->Width;
MyBitmap->Height
= PaintBox1->Height;
//change
the Bitmap's background color to that of the ScrollBox
MyBitmap->Canvas->Brush->Color
= clBtnFace;
MyBitmap->Canvas->FillRect(MyBitmap->Canvas->ClipRect);
//draw
the line on the off screen Bitmap
MyBitmap->Canvas->Pen->Color
= clBlue;
MyBitmap->Canvas->Pen->Width
= 4;
MyBitmap->Canvas->MoveTo(0,0);
MyBitmap->Canvas->LineTo(PaintBox1->Width, PaintBox1->Height);
//copy
it to the onscreen Paintbox
BitBlt(PaintBox1->Canvas->Handle,
0, 0, PaintBox1->Width,
PaintBox1->Height, MyBitmap->Canvas->Handle,
0, 0, SRCCOPY);
}
//--------------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
//Refresh
the PaintBox
BitBlt(PaintBox1->Canvas->Handle,
0, 0, PaintBox1->Width,
PaintBox1->Height, MyBitmap->Canvas->Handle,
0, 0, SRCCOPY);
}
//--------------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete MyBitmap;
} |