2016-11-17 30 views
0

我正在嘗試開發一種方法來證明我的文本在備忘錄/標籤中。但我需要採取角色的X位置。這可能嗎?如果沒有,我如何證明我的文本在firemonkey?我知道這是可能的桌面使用VLC庫,但我沒有發現firemonkey。Firemonkey:如何在備忘錄中檢測字符的X位置

+1

參見[TTextLayout(http://docwiki.embarcadero.com/Libraries/en/FMX.TextLayout.TTextLayout)如果你能做得出來。備忘錄中每行的佈局可通過以下方式訪問:'layout:= TTextLayout(memo1.Lines.Objects [i]);' –

回答

2

我還沒有找到任何獲得字符的X座標的東西。 您可以爲您的字體創建的字符寬度的陣列中,並使方法計算絕對X和字符Y,是這樣的:

for y := 0 to Memo.Lines.Count - 1 do 
    for x := 0 to Memo.Lines[y].Length - 1 do 
    begin 
    AbsoluteX := AbsoluteX + CharWidths[Memo.Lines[y][x]]; 
    AbsoluteY := AbsoluteY + CharHeights[Memo.Lines[y][x]]; 
    // Be careful, for crossplatform using you should use Copy(), not string[n] 
    end; 

對於文本對齊您可以使用此(用於標籤也有VerTextAlign)

Memo.TextAlign := TTextAlign.Trailing; // For right justify 
Memo.TextAlign := TTextAlign.Center; // For center justify 
Memo.TextAlign := TTextAlign.Leading; // For default left justify