10
votes

For aesthetic reasons, I want to show a form on top of another form, just as if it were a component, say like a TPanel. It should resize with the parent, move around as the parent is dragged by its title bar, etc.

-----------------------------
| main form component 1     |
-----------------------------
| main |  the 'embedded'    |  
| form |  form goes here    |
|comp 2|                    |
-----------------------------

can I do that? If so how?


I am now leaning towards MDI...

3
We call that "docking" (embedded form goes here).Warren P

3 Answers

23
votes

Put a panel where you want your embedded form to be at design time. At run time, Create the form, then set the embedded form's Parent property to the panel.

procedure TParentForm.FormCreate(ASender: TObject);
begin
  FEmbeddedForm := TEmbeddedForm.Create(self);

  FEmbeddedForm.Parent := Panel1;
  FEmbeddedForm.Align := alClient;
  FEmbeddedForm.Visible := True;

end;

Edit:

If you want to stop the window title and border from being displayed, add this to the bottom of the FormCreate()

  LForm.Caption := '';
  LForm.BorderStyle := bsNone;

BTW, I am not advocating using parented forms over frames, just answering the question. Frames are great (I use them all the time), but they are not exactly the same as Forms. They are almost exactly like a panel with controls on it.

For instance, a frame does not have an OnCreate event, nor an OnShow event, which can be painful sometimes when you are reusing them and need that sort of behavior.

N@

13
votes
3
votes

Native win32 MDI is considered "out of date". I think you might be looking for something like the JEDI JvDocking library. I use it to emulate MDI but without using the win32 MDI support.