我有一個graphiccontrol
並試圖在畫布上繪製文本。目前我正在做一個Canvas.Textout()
,但因爲手動設置值,如果畫布面積增長的文本沒有。我想讓文字也成長。例如。如何自動繪製基於graphiccontrols大小的文本
{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或文本寬度它會自動修復,但不知道如何?並保留我在同一個地方畫的數字。目前我在大約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;
還,如果有幫助,我想我應該保持大小從而去除所有多餘的代碼變種..
使用'MulDiv'根據畫布大小縮放字體大小 –
我無法在delphi wiki info/help中找到該術語。它是如何工作的? –
將MulDiv輸入Google:http://msdn.microsoft.com/en-us/library/windows/desktop/aa383718.aspx –