【问题标题】:Delphi - Firemonkey Write Out Text to TRectangleDelphi - Firemonkey 将文本写入 TRectangle
【发布时间】:2018-04-16 10:50:12
【问题描述】:

对 Firemonkey 来说还是很陌生。有一个组件要添加到从 TRectangle 下降的表单中。一旦我把它画出来,我想在其中添加文本,但我真的很难找到任何地方记录如何做到这一点。任何人都可以提出任何建议或指出正确的方向吗?

谢谢

【问题讨论】:

  • 在 Firemonkey 中,任何组件都可以有任何其他组件作为父组件,因此只需添加例如一个 Tlabel 作为表单的组件
  • 为那里的迅速回复干杯。感谢您抽出时间伸出援助之手
  • 您可以在设计时将 TLabel 添加到 TRectangle 中。然后将 Alignment 设置为 TLabel 的 Client。就这样。您也可以更改 TextSettings 以进行文本对齐和其他视觉设置。

标签: delphi firemonkey delphi-10-seattle


【解决方案1】:

以 DSM 的注释为基础,这是一个如何在代码中将 TLabel 添加到 TRectangle(或 TRectangle 后代)的示例:

var
  MyLabel: TLabel;
begin
  // Create a TLabel and add it to an existing TRectangle
  MyLabel := TLabel.Create(MyRectangle);

  // Set the Parent to MyRectangle
  MyLabel.Parent := MyRectangle;

  // Align the TLabel in the center of the TRectangle
  MyLabel.Align := TAlignLayout.Center;

  // Center align the text in the TLabel
  MyLabel.TextAlign := TTextAlign.Center;

  // Set the text for the label
  MyLabel.Text := 'Test Label';
end;

【讨论】:

  • 谢谢你,这真的很有帮助。欣赏 Dsm 的回答也是正确的,但包括一个例子是非常有用的,因为它给了我一些可以构建的东西。
猜你喜欢
  • 1970-01-01
  • 2021-12-06
  • 1970-01-01
  • 2013-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多