paintbox没有从定时器方法绘制c ++ builder borland [英] paintbox doesnt paint from timer method c++ builder borland
问题描述
我使用Borland C ++ Builder 6。
I am using Borland C++Builder 6.
我有两种方法:
void __fastcall FDisplay::PaintBox1Paint(TObject *Sender)
void __fastcall FDisplay::TimerLabelsViewTimer(TObject *Sender)
在第一种方法中,我绘制坐标系。
In the first method I draw the coordinate system.
在第二种方法中:
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();
推荐答案
的 OnPaint
事件处理程序的内部。这包括你的线条画。您的 OnTimer
事件处理程序无法直接在PaintBox上绘制,下一次绘制 PaintBox
任何原因。
You must do ALL of the drawing inside of the OnPaint
event handler. That includes your line drawing. Your OnTimer
event handler cannot draw directly on the PaintBox, the drawing will be lost the next time the PaintBox
is painted for any reason.
您可以做的是使用 OnTimer
处理程序存储线图的所需坐标,然后 Invalidate()
PaintBox来表示重绘。然后 OnPaint
事件可以在存储的坐标处绘制线。要擦除该行, Invalidate()
PaintBox,只是不绘制线。
What you can do instead is have the OnTimer
handler store the desired coordinates for the line drawing and then Invalidate()
the PaintBox to signal a repaint. The OnPaint
event can then draw the line at the stored coordinates. To erase the line, Invalidate()
the PaintBox and simply don't draw the line.
private:
TPoint lineStartPos;
TPoint lineEndPos;
...
void __fastcall FDisplay::PaintBox1Paint(TObject *Sender)
{
//...
if (!lineStartPos.IsEmpty() && !lineEndPos.IsEmpty())
{
PaintBox1->Canvas->MoveTo(lineStartPos.x, lineStartPos.y);
PaintBox1->Canvas->LineTo(lineEndPos.x, lineEndPos.y);
}
//...
}
void __fastcall FDisplay::TimerLabelsViewTimer(TObject *Sender)
{
//...
PaintBox1->Invalidate();
}
绘制线:
lineStartPos = Point(693,201);
lineEndPos = Point(770, 187);
PaintBox1->Invalidate();
删除此行:
lineStartPos = TPoint();
lineEndPos = TPoint();
PaintBox1->Invalidate();
这篇关于paintbox没有从定时器方法绘制c ++ builder borland的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!