I am using Borland C++Builder 6.
I have two methods of the form:
void __fastcall FDisplay::PaintBox1Paint(TObject *Sender)
void __fastcall FDisplay::TimerLabelsViewTimer(TObject *Sender)
In the first method I draw the coordinate system.
and in the second method I did:
PaintBox1->Canvas->MoveTo(693,201);
PaintBox1->Canvas->LineTo(770,187);
and the line doesn't appear on the coordinate system.
my second question, how can I erase the line and return to the base paint? Should I do this?
PaintBox1->Invalidate();
PaintBox1->Update();
You must do ALL of the drawing inside of the
OnPaintevent handler. That includes your line drawing. YourOnTimerevent handler cannot draw directly on the PaintBox, the drawing will be lost the next time thePaintBoxis painted for any reason.What you can do instead is have the
OnTimerhandler store the desired coordinates for the line drawing and thenInvalidate()the PaintBox to signal a repaint. TheOnPaintevent can then draw the line at the stored coordinates. To erase the line,Invalidate()the PaintBox and simply don't draw the line.For example:
To draw the line:
To erase the line: