Back


 
 

Docking With Delphi 4 +


I was very impressed by how easy it is to dock controls with Delphi 4 + the first time I tried this.

Giving your program users the ability to dock toolbars, panels, DBGrids etc., gives your programs a modern look and it can be helpful for the users to organize what they want to use or see the way they like it.

To set up a TPanel, a form or TControlBar for docking is not hard at all, these will become the items you want to hold your windows that you want docked.

The first rule is to set the DockSite property to True in the Object Inspector.

Here is a simple example:
 

Start a new project and drop a TPanel on the form and set its Align property to alBottom.
Change the Panel1 DockSite property to True in the Object Inspector.

Next you can also change a controls AutoSize property to true in the Object Inspector, this gives the effect that Panel1 has just appeared to take the control your program users want to dock.

Drop another TPanel on the form, this will be Panel2.
Change the TPanel2 DragKind to dkDock and change its DragMode to dmAutomatic.

Next change the Panel2 color property to clYellow (or any color you like, but different from the main forms color), this is so the panel will stand out when it is docked.

When you run this simple example you will find you can drag Panel2 over to the first panel and then you will also find that you can dock it.
 

Another item of interest is the UseDockManager property.
If you set the UseDockManager property to true then it will cause controls that your program users drop on the panel to conform to the shape of the panel or the existing room on the panel.

In other words if you drop 2 controls on a panel both will take up half the space available.
You can use a button in the above example and add this code:

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
    Panel1.UseDockManager := not Panel1.UseDockManager;
end;

Remember Panel1 is the panel we are using to receive controls.
Run the example again and experiment by dropping Panel2 on Panel1 and clicking on your UseDockManager button, try resizing Panel2 as well.

Docking another form into a panel is easy.

Example 2:
 
 
To dock a form in a panel you start a new project, add a TButton (Button1), add a new form (Form2).

Double-click on Button1 and add this code:

procedure TForm1.Button1Click(Sender: TObject);
begin
    Form2.Show;
end;

Click on Form2 and change these properties in the Object Inspector:

Change its DragKind to dkDock and change its DragMode to dmAutomatic.

Add a TPanel (Panel1) component to Form1 and set its align property to alBottom.

Change these properties in the Object Inspector for Panel1:
Set the DockSite property to True in the Object Inspector.

Make sure UseDockManager is set to True for both Form2 and Panel1.
 

As you can see from the two examples Borland has made docking a simple thing to do.



Back

Hosted by www.Geocities.ws

1