0

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

  • 1
    In Firemonkey any component can have any other component as a parent, so just add e.g. a Tlabel as a component to your form – Dsm Apr 16 '18 at 11:05
  • Cheers for the swift reply there. Appreciate you taking the time to lend a hand – Alexander James Apr 16 '18 at 16:11
  • You can add TLabel into TRectangle in design-time. Then set Alignment to Client for TLabel. That's all. You can change TextSettings for text alignment and other visual settings too. – Abdullah Ilgaz Apr 17 '18 at 12:31

1 Answers1

3

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;
Greg Bishop
  • 517
  • 1
  • 5
  • 16
  • 1
    Thanks for this, this was really helpful. Appreciate Dsm's answer was also correct but including an example is dead useful since it gives me something to build on. – Alexander James Apr 16 '18 at 16:11