Recent

Author Topic: tpanel.autosize purpose!?  (Read 349 times)

speter

  • Full Member
  • ***
  • Posts: 107
tpanel.autosize purpose!?
« on: January 14, 2021, 06:11:59 am »
G'Day Folks,

What is the intended purpose of TPanel's autosize property?

If I place a TPanel on a form and set the autosize property to true, the panel basically disappears (width & height = 0).

If I set the constraints MinHeight=25 & MinWidth=100, the panel is visible; but it is not resized to fit it's caption. I added a button and increased the caption's text in the onclick event handler...

I normally use TPanels as containers - often setting the caption to ''; and never set the panel's autosize=true; but I decided today to use the panel to display a message (rather than putting a TLabel in the panel, which is my normal practice).

I am not sure whether this is a bug or a feature! :)
It certainly isn't a big deal.

cheers
S.

PS: I think I found the answer; if I put a button in the panel; then set the panel.autosize=true (in the designer); then the panel basically matches the button's size...
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.8 / FPC 3.0.4 / Windows 10 (64bit)

lucamar

  • Hero Member
  • *****
  • Posts: 3455
Re: tpanel.autosize purpose!?
« Reply #1 on: January 14, 2021, 10:38:39 am »
PS: I think I found the answer; if I put a button in the panel; then set the panel.autosize=true (in the designer); then the panel basically matches the button's size...

Yes, that's what it's for, to match the panel's size to its contents (plus border spacing, etc.).

How is usually used is that one first fills up the panel with whatever other controls one needs and as a last step sets Autosize to true; otherwise, on an empty panel, it diminish to nothing, to match its ... well, its non-existent "content" ;)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jamie

  • Hero Member
  • *****
  • Posts: 4053
Re: tpanel.autosize purpose!?
« Reply #2 on: January 14, 2021, 11:09:27 pm »
yeah, maybe it shouldn't auto size with no child controls.
The only true wisdom is knowing you know nothing

lucamar

  • Hero Member
  • *****
  • Posts: 3455
Re: tpanel.autosize purpose!?
« Reply #3 on: January 15, 2021, 03:13:25 am »
yeah, maybe it shouldn't auto size with no child controls.

Depends of what you mean to do with it, because this behaviour lends itself to some stunning* effects if you create its contents at run-time depending on some conditions and/or you want it to "auto-dissapear" if left empty but be there as e.g. a placeholder; and you can always use constraints if you want an empty panel to, say, mimic a button or something like that. As such it's safest, IMHO, that when you order it to Autosize it does so, whatever the outcome.


* OK, maybe calling it "stunning" is stretching words a bit ... :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018