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.

Advertisements

One thought on “How to have a blue FMX TPanel

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s