Recent

Author Topic: Container like TPanel which resizes itself to match its child controls?  (Read 2592 times)

Joanna

  • Hero Member
  • *****
  • Posts: 1429
Re: Container like TPanel which resizes itself to match its child controls?
« Reply #15 on: February 06, 2024, 01:44:17 pm »
I might need to find better way to keep certain controls together. Maybe by putting them into a tpanel. Other than that , the flow panel works fairly well and I’m replacing most of my frames with tflowpanel descendants.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

rvk

  • Hero Member
  • *****
  • Posts: 6762
Re: Container like TPanel which resizes itself to match its child controls?
« Reply #16 on: February 06, 2024, 01:49:11 pm »
I might need to find better way to keep certain controls together. Maybe by putting them into a tpanel. Other than that , the flow panel works fairly well and I’m replacing most of my frames with tflowpanel descendants.
Yes. TFlowPanel has a certain use-case for when the parent control changes in size (i.e. the flowpanel itself or the screen).
Then it does a good job of rearranging the flow.

You can also put a TPanel on a TFlowPanel if you want some space aroung a TLabel or Label/Input combo. The TPanel will flow in its parent naturally.

It wasn't exactly what was asked by TS, namely a parent which will resize depending on its children (which TPanel.AutoSize does).
The TFlowPanel rearranges its children depending on its own size.
But yes... both have their own advantages.

Joanna

  • Hero Member
  • *****
  • Posts: 1429
Re: Container like TPanel which resizes itself to match its child controls?
« Reply #17 on: February 06, 2024, 02:41:44 pm »
I’ve never had much luck with autosize, maybe I’m doing something wrong. I ended up using the width of the text in controls to determine what size they should be. If I remember correctly, I once tried to use autosize on  a combobox but it didn’t size to fit widest item
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

wp

  • Hero Member
  • *****
  • Posts: 12864
Re: Container like TPanel which resizes itself to match its child controls?
« Reply #18 on: February 06, 2024, 03:34:40 pm »
Is there some container like TPanel which resizes itself to match its child controls?

If the child controls are stacked and resized either vertically or horiziontally the container expands to match the new size?

Of course the children will have to be aligned ie alTop,alClient etc, but enlarging one of them will push those below or to the side of it push against the containser and enlarge it, and reducing them will also reduce the seize of the container.
What's wrong with TPanel? TGroupBox will work as well. Follow this description:

Just drop any controls on a TPanel (or a TGroupBox). Do not touch their Align! Set the panel's AutoSize to true and the panel will change its size such that it closely contains the controls. you may notice that the top-most/left-most control has been moved into the upper left corner; if you want to change its position do this by adjusting its BorderSpacing.Left and BorderSpacing.Top parameters. Except for this top/left control, all other controls can be freely moved with the mouse, and the size of the panel adjusts when a control would reach beyond the current right/bottom bounds. Do not drag controls such that their left or top sides go out of the left/top borders of the panel (or at least do this very slowly); the control will stop at the left/top edges, but the opposite side of the panel will move quite quickly. This sounds wrong, maybe it is, but once you've accepted that nothing can be beyond the top/left edge of the top/left control you will not attempt to do so.
« Last Edit: February 06, 2024, 04:49:28 pm by wp »

 

TinyPortal © 2005-2018