Reputation: 16186
I have tried to embed a form inside a Scrollbox:
procedure TfrmMain.FormCreate(Sender: TObject);
var
Control:TControlView;
begin
Control := TControlView.Create(Self);
Control.BorderIcons := [];
Control.parent := ListControls;
Control.width := 800;
ListControls.AddObject(Control);
Control.Visible:= True;
end;
However the form is displayed behind tfrmMain and outside the bouns of the form.
My idea is put a form inside a panel, and both inside scrollbox. Each form represent a complex item with several controls and stuff (the reason to not use ListBox? Firemonkey control creation is far harder than simply do a form and embed it)
Upvotes: 7
Views: 6776
Reputation: 5566
Here is a step by step instruction:
Design your embedded form. Place a TLayout with alignment alClient
onto your form. Place all controls inside this layout:
TFormEmbedded = class(TForm)
LayoutMain: TLayout;
//....
end;
Design your master form.
Place a Layout onto your master form, that shall later contain the subform.
Add the following code to FormCreate of your master form:
procedure TFormMaster.FormCreate(Sender: TObject);
var
SubForm: TFormEmbedded;
begin
SubForm := TFormEmbedded.Create(Self);
SubForm.LayoutMain.Parent := Self.LayoutSubForm;
end;
Thanks to nexial for the original description.
Upvotes: 0
Reputation: 399
You have to set the container control's ClipChildren
property to true
.
Upvotes: 0
Reputation: 4211
The secret is in how you design your child form.
You need to create a control as a container, say a TLayout (no styling), TRectangle (Basic styling) or TPanel. I'd go with the TLayout. Decide on a name for your container, say 'Container' for the sake of argument. Now create you child form and simply assign the Parent of Container to your parent object.
So, from your code above (I'm assuming TControlView is your child form):
procedure TfrmMain.FormCreate(Sender: TObject);
var
Control:TControlView;
begin
Control := TControlView.Create(Self);
Control.Container.parent := ListControls;
Control.Container.width := 800;
end;
Upvotes: 8