It's possible to set the Alignment on a TForm, say set one form to alTop and another to alClient - whereby the two forms take up the whole screen area in the obvious way. Is this a sensible thing to do in an application?
I also notice that anchors are exposed on forms - but I can't think what they would be useful for (resolution changes? MDI apps?) Any ideas?
Edit: I've made a video about this post to make things clearer.
You can use a TForm
like an ordinary control by setting its Parent
property:
procedure TForm1.Button1Click(Sender: TObject);
begin
frmEmbed:= TForm.Create(Self);
frmEmbed.Parent:= Self;
frmEmbed.Width:= 50;
frmEmbed.Height:= 50;
frmEmbed.Align:= alRight;
frmEmbed.Anchors:= [akLeft, akBottom];
frmEmbed.Visible:= True;
end;
you should comment frmEmbed.Align:= alRight;
line to see how Anchors
property works.
If you are interested where the above is used: parented form without a caption bar is an alternative to TFrame
; frames were not available with early Delphi versions, so parented forms were used instead. You can find them in legacy code.
You can place a Form inside another Form. Dunno how good that would work though. In Delphi1 times there were special 3rd-party controls to route the event. Today it seems to more or less work out of the box, except for modal dialogs. Try like this:
procedure TMainForm.Button1Click(...);
begin
with TForm.Create(Self) do begin
Caption := 'Internal one';
Parent := Self;
Visible := True;
end;
end;
Perhaps anchors and align would make sense in this setup. Afterall this seems how new "one-window" IDE layout is implemented.
One simple case is for a captionless form (e.g. win-8 metropolis style) you can anchor an exit button to upper right corner.
But the best use is to simplify making a complex form responsive to size changes... Using the akLeft and akRight, you can make a horizontal control fill space horizontally. Using all 4 anchors is similar to setting a client to alclient, just without needing to surround it with other panels.
Much of what you can do with anchors can also be done with many panels, but as the form becomes more complex it will get messy sometimes requiring several levels of panels upon panels.
Of course using a combination of panels and anchors will often be the best answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With