摘要: Instructions on how to use the TDockTabSet component to make advanced docking user interfaces.
Introduction
This article discusses the use of the TDockTabSet component that was originally introduced in Delphi 2005.
Creating the applications main form
Create a File | New | VCL Forms Application - Delphi for Win32.
Setting up the main form
Locate the TDockTabSet component on the additional page in the Tool Palette and drop it onto the main form.
Set the following properties:
Align
alLeft
DockSite
False
ShrinkToFit
True
Style
tsModernTabs
TabPosition
tpLeft
Width
25
You may want to use the tsModernPopup tab style instead of the tsModernTabs. The download that accompanies this article does.
To keep the TDockTabSet component company on the form, drop the following components and modify the properties as indicated.
TPanel
Align
alTop
BevelKind
bkTile
BevelOuter
bvNone
Caption
TPanel
Align
alLeft
BevelOuter
bvNone
DockSite
True
Name
pDockLeft
Width
0
TSplitter
Align
alLeft
TMemo
Align
Client
Drop a TButton on the top aligned Panel and set its caption to Show Form
Set the Forms caption to TDockTabSetDemo Application
Name the form frmMain and save the unit as MainForm
If you name your components differently remember to reference the correct name when adding the source code.
The main form of your application should look something like the following.
The setting of the all important property
There is one more property that needs to be set on the TDockTabSet before we can continue. Set the DestinationDockSite to be the left aligned panel. Called pDockLeft in this article.
Now it's time to create another form for the application. There are now 3 ways this can be done in Delphi 2006 and I'll mention all of them:
Select the File | New | Form for Win32 or
Click on the Project Manager
In the Tool Palette you will see the object repository items get added.
Locate the Delphi Projects | Delphi Files category.
Double click on the Form icon to create a New Form.
Right click on the project manager and select the Add New menu item. From the sub menu select Form.
I prefer the 3rd method, which is new to Delphi 2006 and I've discussed previously on my blog. Name the new form frmDock and save the unit as DockForm. In the code editor for this unit do the following.
Delete the global frmDock: TfrmDock variable from the forms implementation section, it isn't required
Make sure the form isn't in the list of forms that are created automatically (I always turn this option off by default). To do this select the Project | Options menu item and move frmDock to the Available Forms list for the Forms option page.
Add an OnClose event that contains the following code
6.Finally modify the following properties on the dock form
BorderStyle
bsSizeToolWin
DragKind
dkDock
DragMode
dmAutomatic
You may also want to modify the size of the frmDock form to not be so wide.
That is the form that will be docked completed. Time to write some in the main unit!
Switch to the MainForm unit now and make the following changes.
1.Invoke the Use Unit dialog (Alt+F11 or File | Use Unit) and select the DockForm unit.
2.Create an OnClick event for the TButton with the following code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
procedureTfrmMain.Button1Click(Sender: TObject);
var
i: Integer;
begin
// close all previously dockable forms before recreating
请发表评论