我有一个graphiccontrol
并试图在画布上绘制文本。目前我正在做一个Canvas.Textout()
但是因为如果画布区域增长文本没有,我会手动设置值。我想让文字也成长。例如。
{Sets the cards power and draws it on the tcard}
//------------------------------------------------------------
procedure TCard.DrawLPower(value: string);//left number
//------------------------------------------------------------
begin
if fbigcard = false then
begin
canvas.Font.Size := 8;
canvas.font.color := TColor($FFFFFF);
Canvas.TextOut(1,1,value);
end
else
begin
canvas.font.color := TColor($FFFFFF);
canvas.Font.Size := 12;
Canvas.TextOut(1,7,value);
canvas.Font.Color := CLBlack;
end;
end;
我检查卡片/画布是否很大,如果是的话,它会发出 1,7,如果它不大,它会发出 1,1。我在想,如果我使用 textheight 或 text width 方法,它会自动解决这个问题,但不确定如何?并将我绘制的数字保持在同一个位置。目前我在大约 3 个地方这样做,另外两个是。
{sets cards def and draws it to the tcard}
//------------------------------------------------------------
procedure TCard.DrawLDefence(value: string); //right number
//-------------------------------------------------------------
begin
if fBigcard = false then
begin
canvas.font.color := TColor($FFFFFF);
canvas.Font.Size := 8;
canvas.TextOut(32,1,value);
canvas.Font.Color := CLBlack;
end
else
begin
canvas.font.color := TColor($FFFFFF);
canvas.Font.Size := 12;
canvas.TextOut(115,7,value);
canvas.Font.Color := CLBlack;
end;
end;
{Sets and draws the cost to the TCard}
//-------------------------------------------------------------
procedure TCard.DrawLCost(value :string); //cost
//-------------------------------------------------------------
begin
if fbigcard = false then
begin
canvas.font.size := 8;
canvas.font.color := TColor($FFFFFF);
Canvas.textout(19,1,inttostr(CCost));
end
else
begin
canvas.font.size := 12;
canvas.font.color := TColor($FFFFFF);
Canvas.textout(65,7,inttostr(CCost));
canvas.Font.Color := CLBlack;
end;
end;
如果它有帮助,我想我应该将大小保持为 var 从而删除所有额外的代码..