如何在 TWebMemo 组件内居中放置文本

问题描述 投票:0回答:2

我试图将我的文本在 TWebMemo 组件中居中,但我无法做到这一点,有人知道如何将文本居中吗?

delphi center tms tms-web-core
2个回答
0
投票

将 TMemo 的 Alignment 属性设置为 taCenter 而不是 taLeftJustify。


0
投票

要将文本在 Delphi 中的

TMemo
组件内居中,请使用
Alignment
属性设置文本对齐方式。不幸的是,
TMemo
组件中没有内置属性可以使文本居中。但是,您可以使用
TMemo
设置
TStringList
中每行文本的对齐方式。在您的表单中添加一个
TMemo
组件。将
Alignment
中每行的
TStringList
属性设置为
taCenter
以使文本居中对齐。将
TStringList
组件分配给
TMemo

procedure CenterTextInMemo(Memo: TMemo);
var
  TextLines: TStringList;
  i: Integer;
begin
  TextLines := TStringList.Create;
  try
    // Set the text alignment to center for each line
    for i := 0 to Memo.Lines.Count - 1 do
    begin
      TextLines.Add(Format('%s=%d', [Memo.Lines[i], Ord(taCenter)]));
    end;
    
    // Assign the TStringList back to the Memo to apply the center alignment
    Memo.Lines.Assign(TextLines);
  finally
    TextLines.Free;
  end;
end;
© www.soinside.com 2019 - 2024. All rights reserved.