As we all know, TPanel is a container for other visual components (TLabel, TEdit etc).
However, it seems that we can place only new components (from the
component palette) onto an existing TPanel and the VCL framework will then automatically make the TPanel their parent).
I wonder if there's a way to place existing visual components (those that are already on our VCL form) onto a TPanel. I've tried
Placing components on an existing TPanel (this doesn't work because the framework will not make the TPanel their parent)
Manually editing the form's dfm file (the components on the TPanel are now invisible -- a bug?)
Explicitly setting a component's Parent property in code (
Label1is visible even whenPanel1height is set to 0)Label1->Parent = Panel1;
Neither of the above worked but this seems to be such a basic thing that it has to be a way to do this.
Thank you
Based on my experience with VCL (I use Delphi but I think the same is valid for C++), I know 3 ways to change the
Parentof an already existing control at design time:Drag and drop the
Controlinto the desiredParentfrom the Structure windowSelect the
Control, cut it Ctrl + X, select the desiredParentand paste Ctrl + V. In this way theControlwill be pasted as child control of the desiredParentManually edit the DFM file. Doing this way, you have to pay attenction to the
LeftandTopproperties, because theControlcould be placed outside the newParentand it could seems invisible. In this case I suggest to set the control'sLeftandTopto0in order to be sure theControlwill be visible inside its newParent