How to have a blue FMX TPanel

The short answer is: don’t try. In the VCL, TPanel plays the part of the basic container control. In FMX, in contrast, it doesn’t – TLayout does that. The whole point of the FMX TPanel is be a basic container control with a certain, predefined style. TLayout, in contrast, is a basic container control with no predefined style.

Anyhow, if a person really must use TPanel yet disregard its styling, I would advise handling its OnApplyStyleLookup event by getting a reference to its embedded TRectangle object, and setting the TRectangle’s Fill property accordingly:

procedure TForm1.Panel1ApplyStyleLookup(Sender: TObject);
var
  Rectangle: TRectangle;
begin
  Rectangle := (Sender as TFmxObject).Children[0] as TRectangle;
  Rectangle.Fill.Color := TAlphaColors.Blue;
end;

You’ll need to ensure FMX.Objects is in the uses clause if it isn’t already.

One thought on “How to have a blue FMX TPanel

  1. Pingback: How to have a blue FMX TPanel, redux | Delphi Haven

Leave a comment