Search code examples
firemonkeyc++buildervcl

How to add a border to TText or TLabel in FireMonkey?


I usually code using VCL in C++Builder, but now I'm using FireMonkey for a multi-platform project, and I have some difficulties.

In VCL, it is easy to set a solid rectangular border for TStaticText by setting its BorderStyle property to sbsSingle.

In FireMonkey, there is no TStaticText control, instead there is TText, but I'm not able to set a solid rectangular border for it.

Also, a TLabel with a border should be OK, but even in this case I don't know how to set a border for it.

Can anyone help me to do this?


Solution

  • As you noted, there are no text control with borders. However, it is easy to make one, by combining a TRectangle and a TLabel (or a TText).

    • Add a TRectangle and set its Stroke (and Fill) properties as you wish.
    • Drop a TText or TLabel on the rectangle and set its properties as needed.

    Example:

      object Rectangle1: TRectangle
        Fill.Kind = None
        Position.X = 50.000000000000000000
        Position.Y = 120.000000000000000000
        Size.Width = 181.000000000000000000
        Size.Height = 41.000000000000000000
        Size.PlatformDefault = False
        Stroke.Color = claCrimson
        Stroke.Thickness = 4.000000000000000000
        object Text1: TText
          Align = Client
          Size.Width = 181.000000000000000000
          Size.Height = 41.000000000000000000
          Size.PlatformDefault = False
          Text = 'Here'#39's some text'
          TextSettings.Font.Size = 20.000000000000000000
          TextSettings.Font.Style = [fsBold]
          TextSettings.FontColor = claBlue
        end
      end
    

    enter image description here