because you use Canvas->
instead of PaintBox1->Canvas->
- so you draw on the
this->Canvas->
which is Form1
in your case
I assume you want to use bitmap as back buffer
- then you should use
DrawingBoard->Canvas
instead of all PaintBox1->Canvas->
- except the last in
FormShow
- also I would use
OnPaint
instead of OnShow
...
- also you should use client size not size
- also do not draw bitmap offseted to
PaintBox
the VCL translate the coordinates by itself
- do not forget to clear the backbuffer before rendering (unless you are doing some cumulative drawing/effect)
Something like this:
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DrawingBoard = new Graphics::TBitmap;
DrawingBoard->Width = PaintBox1->ClientWidth;
DrawingBoard->Height = PaintBox1->ClientHeight;
}
void __fastcall TForm1::PaintBox1Paint(TObject *Sender)
{
DrawingBoard->Canvas->Pen->Color = clBlack;
DrawingBoard->Canvas->Brush->Color = clWhite;
DrawingBoard->Canvas->FillRect(TRect(0,0,DrawingBoard->Width,DrawingBoard->Height));
DrawingBoard->Canvas->MoveTo(256,216);
DrawingBoard->Canvas->LineTo(270,250);
PaintBox1->Canvas->Draw(0,0,DrawingBoard);
}
[Notes]
- if your PaintBox is resize-able then add its OnResize event and resize the bitmap inside ...