Firemonkey:如何在备忘录

时间:2016-11-17 13:39:27

标签: delphi text firemonkey

我正在尝试开发一种方法,在备忘录/标签中证明我的文字。但我需要取一个角色的X位置。这可能吗?如果没有,我怎么能在firemonkey中证明我的文本?我知道这可以在使用VLC库的桌面上实现,但我找不到firemonkey。

1 个答案:

答案 0 :(得分: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