Realize docking function in Delphi7

zhaozj2021-02-16  69

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 Add OnDockDrop, OnDockover, Onundock Events as follows:

Procedure tfrmmain.pnlleftUndock (Sender: Tobject; Client: tcontrol;

NEWTARGET: TwinControl; VAR Allow: Boolean;

Begin

? if (sender as tpanel) .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);

? END

? Else

? begin

?? if state = dsdragleave the

?? 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;

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 the

?? 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 dam

? 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.

转载请注明原文地址:https://www.9cbs.com/read-15552.html

New Post(0)