Delphi XE6 TForm.AutoSize

丶灬走出姿态 提交于 2020-01-15 03:42:13

问题


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 ?


回答1:


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;



回答2:


Not align, use anchors:

t.Anchors:=[TAnchorKind.akTop];

This is from my XE5 (have no XE6)



来源:https://stackoverflow.com/questions/24695147/delphi-xe6-tform-autosize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!