When I drag and dock the Panel3 for the second time it takes the full area of Panel1 and hides Panel2.
How to do that always work as the first time?
Add a Panel3.OnStartDock handler:
procedure TForm1.Panel3StartDock(Sender: TObject;
var DragObject: TDragDockObject);
begin
Panel3.Align:=alNone;
end;
When I 'undock' the Panel3 is moved into a separated window, then if I close that window, How I can open the window again?
To restore the panel to its original position you'll have to save its initial Top and Left values for later reference. In TForm1's private section add two fields
...
private
OriginalLeft: integer;
OriginalTop: integer;
end;
Add a TForm1.OnShow handler to store the values:
procedure TForm1.FormShow(Sender: TObject);
begin
OriginalLeft:=Panel3.Left;
OriginalTop:=Panel3.Top;
end;
Drop a TPopupMenu on the form, add one menu item with a caption such as "Restore hidden". Set the form's Popupmenu property to point to the added popupmenu; and create a menuitem OnClick handler:
procedure TForm1.MenuItem1Click(Sender: TObject);
begin
Panel3.Left:=OriginalLeft;
Panel3.Top:=OriginalTop;
panel3.Align:=alNone;
Panel3.Visible:=True;
panel3.Parent:=Self;
end;
That should do it. You might prefer to use a main menu, or a 'Restore' button or some other way to implement the changes to Panel3's properties needed to restore it.