Use this FireMonkey panel trick to change the color of a Delphi FireMonkey panel or make a FireMonkey panel transparent
I have seen some complex solutions to achieve this, but this is really quite easy to do. You just need one line of code.
Change the panel color
(Panel1.Controls as TShape).Fill.Color := TAlphaColorRec.Red;
How does it work ?
More robust code
if (Panel1.ControlsCount >= 1) and (Panel1.Controls is TShape) then (Panel1.Controls as TShape).Fill.Color := TAlphaColorRec.Red; // uses System.UITypes
Want more – lets make the panel transparent
Now that you know the magic trick of the TPanel guts being a TShape, you can go further and manipulate the shape to make the panel transparent … like this
if (Panel1.ControlsCount >= 1) and (Panel1.Controls is TShape) then (Panel1.Controls as TShape).visible := FALSE;
Is this Future Proof ?
- Add a TRect to the panel to show the color that you want. Thats pretty much the same technique that I use above, but you will feel more in control because you created it.
- Use Delphi Styles.
+1 this post
- Oracle & Delphi software developer based in Perth, Western Australia
- Australian Delphi User Group – President
- Australian Oracle User Group – WA Committee Member
Available to do remote presentations to user groups on Delphi and Oracle topics