How to Back Color Setting (Multi Device Application)

0

Hello

Please tell me how to change the background color of TLabel dynamically.
There is no item to change the background color in the property of TLabel ?

C++ Tokyo 10.2.1 Multi Device application

Thanks

  • Accepted Answer

    Friday, March 02 2018, 02:23 PM - #Permalink
    0

    Is this what you need with this code?  It's somewhat of a workaround, but it does let you change the background color of TLabel dynamically.

    type

      TForm2 = class(TForm)

        Label1: TLabel;

        Button1: TButton;

        procedure Label1Paint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);

        procedure Button1Click(Sender: TObject);

        procedure FormCreate(Sender: TObject);

      private

        fLabelColor: TAlphaColor;

      public

        { Public declarations }

      end;

     

    var

      Form2: TForm2;

     

    implementation

     

    {$R *.fmx}

     

    procedure TForm2.Button1Click(Sender: TObject);

    begin

      fLabelColor := TAlphaColorRec.Red;

      //- This is a workaround, forcing the label to redraw by setting its

      //- visibility to false and back to true (causes invalidate)

      Label1.Visible := not Label1.Visible;

      Label1.Visible := not Label1.Visible;

    end;

     

    procedure TForm2.FormCreate(Sender: TObject);

    begin

      fLabelColor := TAlphaColorRec.Yellow;

    end;

     

    procedure TForm2.Label1Paint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);

    begin

      Canvas.Fill.Color := fLabelColor;

      Canvas.FillRect(ARect,0,0,[],1);

    end;

    The reply is currently minimized Show
  • Responses (0)
    • There are no replies here yet.
    Your Reply

    Please login to post a reply.........