Delphi XE6 TForm.AutoSize
Asked Answered
A

2

2

I've code in Delphi XE2 who work perfectly. But in Delphi XE6 it doesn't work. I create a Tform with the property AutoSize to true. I use a TPanel align alTop with a button for create some another panels.

procedure TForm2.Button1Click(Sender: TObject);
var
   t :TPanel;
begin
   t := TPanel.Create(self);
   t.Parent := self;
   t.Align := alTop;
end;

The form doesn't auto size. If I want to see all my panels I have to move the form (or try to resize, ....).

Have you any idea's ?

Aeri answered 11/7, 2014 at 10:1 Comment(7)
Seems to work ok in XE5. Installing XE6 om my laptop, may take a while ...Cacophonous
AutoSize -> Adjust form size automatically. alTop -> Adjust panel size automatically. No good using both, one of them should have precedence, which would purely depend on implementation detail.Frottage
@SertacAkyuz I'm not so sure – alTop does more than adjust size, it positions controls too.Shamus
@David - What it does more does not change the fact that it is resized automatically to fit in its parent.Frottage
@SertacAkyuz It seems to me that AutoSize and Align are expected to work together. When you put aligned controls in an auto-sized container, the controls are no longer resized. The controls are positioned, and the container is resized to match the size of the controls. Not that I can find any documentation to that effect.Shamus
@David - Incomplete documentation wouldn't surprise me. However it's not straightforward to implement.. Consider an alTop and an alBottom panel with different widths... The outcome would still depend on implementation detail.Frottage
@SertacAkyuz Yes it would.Shamus
S
3

This is indeed a change in behaviour. I can reproduce what you report. Namely that your code results in the form size changing in XE2, but not in XE6.

To work around this you can manually call AdjustSize:

procedure TForm1.Button1Click(Sender: TObject);
var
  Panel: TPanel;
begin
  Panel := TPanel.Create(self);
  Panel.Parent := Self;
  Panel.Top := ClientHeight;
  Panel.Align := alTop;
  AdjustSize;
end;
Shamus answered 11/7, 2014 at 10:36 Comment(1)
Panel.Parent := Self; triggers OnFormResize event in XE5, but not in XE6. I'm puzzled why this change in behaviour was introduced.Cacophonous
P
0

Not align, use anchors:

t.Anchors:=[TAnchorKind.akTop];

This is from my XE5 (have no XE6)

Peckham answered 11/7, 2014 at 10:31 Comment(1)
Make sure to position and size the Panel where you want it before you then Anchor it.Oratory

© 2022 - 2024 — McMap. All rights reserved.