嘿,我想在弹出一个表格时画一些东西。我注意到了OnPaint
,但它并没有显示我的绘图。当我将它添加到按钮时,它确实显示了我想要绘制的内容。
这是我画的:
void TSelectElementForm::DrawLinesInLayout()
{
EraseLayOut(); //draws a new square over the previous lines
int X_origin, Y_origin;
int X1, Y1, X2, Y2, X3, Y3, X4, Y4;
int VectorSize;
int scale;
X_origin = Layout->Left +5;
Y_origin = Layout->Top +5;
Canvas->Pen->Color=clRed;
Canvas->MoveTo(X_origin,Y_origin);
Canvas->LineTo(X_origin,Y_origin+10);
Canvas->MoveTo(X_origin,Y_origin);
Canvas->LineTo(X_origin+10,Y_origin);
VectorSize = ElementVector[Index].vectorLP.size();
scale = CalculateScale();
for(int i =0; i < VectorSize; i++)
{
int LPX = ElementVector[Index].vectorLP[i].X;
int LPY = ElementVector[Index].vectorLP[i].Y;
int BeginX = ElementVector[Index].el_beginX;
Canvas->Pen->Color=clLime;
X1 = X_origin + ((LPX - BeginX) / scale);
Y1 = Y_origin + (LPY / scale);
if(i == 0)
{
Canvas->MoveTo(X1, Y1);
}
else
{
Canvas->LineTo(X1, Y1);
}
}
}
因此,当我在按钮中调用此方法时,它会起作用,但是当我在OnShow
事件或OnPaint
事件中调用此方法时,它不会绘制任何内容。
奇怪的是,当我只是使用drawLine()
方法(绘制1行)和OnPaint
事件创建一个新项目时它才能正常工作。怎么可能?
所以,只需2个问题: