Alexander James
Alexander James

Reputation: 33

Delphi - Firemonkey Write Out Text to TRectangle

still pretty new to Firemonkey. Got a component I'm adding to a form which descends from TRectangle. Once i've drawn it out, I want to add text into it but I'm really struggling to find anywhere which documents how to do this. Can anyone suggest anything or point me in the right direction?

Thanks

Upvotes: 0

Views: 577

Answers (1)

Greg Bishop
Greg Bishop

Reputation: 529

To build on DSM's comment, this is an example of how to add a TLabel to a TRectangle (or a TRectangle descendent) in code:

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;

Upvotes: 3

Related Questions