Realize docking function in Delphi7
We often need to use a sub-window to stop on the main window during the development of the Delphi7 development application. Cheng Docking, I will introduce you to a simple way to make it.
1. Add four panels and four splitter to the main window, set the left and right sides of the opposite.
2, set the attribute Docksite property of four panels to True.
3, left and right PANEL added
OnDockDrop, OnDockover, Onundock event is as follows:
Procedure tfrmmain.pnlleftUndock (Sender: Tobject; Client: tcontrol;
NEWTARGET: TwinControl; VAR Allow: Boolean;
Begin
IF (sender as tpner) .visibleDockClientCount = 1
THEN
Begin
Sender as tpanel .width: = 1;
END;
END;
Procedure tfrmmain.pnlleftdockdrop (Sender: TOBJECT)
Source: TDRAGDOCKOBJECT; X, Y: Integer;
Begin
(Sender as tpanel) .width: = max (Source.Control.undockwidth, (Sender as tpanel) .width);
END;
Procedure tfrmmain.pnlleftdockover (Sender: TOBJECT)
Source: TDRAGDOCKOBJECT; X, Y: Integer; State: TDRAGSTATE
VAR Accept: boolean;
Begin
IF state = dsdragenter
THEN
Begin
(Sender as tpanel) .width: = max (Source.Control.undockwidth, (Sender as tpanel) .width);
ELSE BEGIN
IF state = dsdragleave
THEN
Begin
Sender as tpanel .width: = 1;
End; end;
Left and right PANEL response event code.
4, up and down PANEL Add OnDockDrop, OnDockover, Onundock Events as follows:
Procedure tfrmmain.pnlbottomundock (Sender: Tobject; Client: tcontrol;
NEWTARGET: TwinControl; VAR Allow: Boolean;
Begin
IF (sender as tpanel) .dockClientCount = 1
THEN
Begin
Sender as tpanel .height: = 1;
END;
Procedure tfrmmain.pnlbottomdockdrop (Sender: TOBJECT)
Source: TDRAGDOCKOBJECT; X, Y: Integer;
Begin
(Sender as tpanel) .height: = max (Source.control.undockHeight, (Sender as tpanel) .height);
END;
Procedure tfrmmain.pnlbottomDockover (Sender: TOBJECT)
Source: TDRAGDOCKOBJECT; X, Y: Integer; State: TDRAGSTATE
VAR Accept: Boolean; Begin
IF state = dsdragenter then
Begin
(Sender as tpanel) .height: = max (Source.control.undockHeight, (Sender as tpanel) .height);
end
Else Begin
IF state = dsdragleave
THEN
Begin
Sender as tpanel .height: = 1;
End; end;
The two PANEL response event code are the same.
5. Creating a new form is used to stop to the main form.
6, set the new form Dragkind to DKDOCK, DragMode is Dmautomatic.
7, add the following code in the new form onclose event:
IF self.hostdocksite <> nil
THEN
Begin
Self.manualdock (nil);
END;
Action: = Cahide;
8, setting up a new form is not automatically created.
9. Create a new form in the main body and display it. Remember: Use Show, don't use ShowModal.
This approach is a non-standard method that requires more detailed control, it is best to refer to Delphi's docking example. If you change a panel in this example to TabControl or PageConrol, you can get better results, but the code needs to change slightly, interested buddies can try.