Jump to content
JimKueneman

Layouts

Recommended Posts

I trying to learn SMS.  I have dropped a panel then 3 buttons _inside_ the panel.  I want them to all align to the left with no space between the buttons or between the buttons and container panel.  

 

This does not do it.  What am I missing?

 

Thanks 

Jim

procedure TForm1.InitializeObject;
begin
  inherited;
  {$I 'Form1:impl'}
  FLayout := Layout.Bottom(
               Layout.Margins(3).Spacing(3),
               [
               W3Panel1
               ]);
  FTabLayout := Layout.Left(Layout.Margins(0).Spacing(0),
                [
                Layout.Left(W3Button1),
                Layout.Left(W3Button2),
                Layout.Left(W3Button3)
                ]);
end;
 
procedure TForm1.Resize;
begin
  inherited;
  FLayout.Resize(Self);
  FTabLayout.Resize(W3Panel1);
end;

Share this post


Link to post
Share on other sites
An easy way would be:

 

{ on InitializeForm }

FLayout :=

  Layout.Client([

    Layout.Client(W3Panel1),

    Layout.Bottom(Layout.Height(40),

      Layout.Left(Layout.Stretch, [btn1, btn2, btn3]))

  ]);

 

{ on InitializeObject }

 


W3Panel1 := TW3Panel.Create(Self);

W3Panel1.Width := 585;

W3Panel1.Top := 272;

W3Panel1.Left := 72;

W3Panel1.Height := 86;

W3Panel1.Name := 'W3Panel1';

 

btn1 := TW3Button.Create(Self);

btn1.Caption := 'btn1';

btn1.Width := 128;

btn1.Top := 368;

btn1.Left := 96;

btn1.Height := 32;

btn1.Name := 'btn1';

 

btn2 := TW3Button.Create(Self);

btn2.Caption := 'btn2';

btn2.Width := 128;

btn2.Top := 368;

btn2.Left := 240;

btn2.Height := 32;

btn2.Name := 'btn2';

 

btn3 := TW3Button.Create(Self);

btn3.Caption := 'btn3';

btn3.Width := 128;

btn3.Top := 368;

btn3.Left := 384;

btn3.Height := 32;

btn3.Name := 'btn3';

 

{ on resize }


if Assigned(FLayout) then

     FLayout.Resize(Self);


Share this post


Link to post
Share on other sites

You have to put your Layout code in the InitializeForm procedure. When InitializeObject is called, the size properties are not present at this time.

 

And in the Resize procedure, you have to check if the Layout is already assigned.

  if Assigned(FLayout) then
  begin
    FLayout.Resize(self);
    FTabLayout.Resize(W3Panel1);
  end;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×