• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

使用Delphi自带的TDockTabSet组件实现停靠功能(Jeremy North)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

源地址:http://edn.embarcadero.com/article/33446

摘要: 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.

  1. 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.
  1. TPanel

Align alTop
BevelKind bkTile
BevelOuter bvNone
Caption

  1. TPanel

Align alLeft
BevelOuter bvNone
DockSite True
Name pDockLeft
Width 0

  1. TSplitter

Align alLeft

  1. TMemo

Align Client

  1. Drop a TButton on the top aligned Panel and set its caption to Show Form
  2. Set the Forms caption to TDockTabSetDemo Application
  3. 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:

  1. Select the File | New | Form for Win32 or
  2. Click on the Project Manager
    1. In the Tool Palette you will see the object repository items get added.
    2. Locate the Delphi Projects | Delphi Files category.
    3. Double click on the Form icon to create a New Form.
  3. 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.
  1. Delete the global frmDock: TfrmDock variable from the forms implementation section, it isn't required
  2. 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.
  3. Add an OnClose event that contains the following code

1
2
3
4
5
6
7
8
9
procedure TfrmDock.FormClose(Sender: TObject; var Action: TCloseAction);
 
begin
 
  ManualFloat(Rect(0, 0, 0, 0));
 
  Action := caFree;
 
end;

4.Add an OnStartDock event that contains the following code

1
procedure TfrmDock.FormStartDock(Sender: TObject; var DragObject:<br data-filtered="filtered"><br data-filtered="filtered">  TDragDockObject);<br data-filtered="filtered"><br data-filtered="filtered">begin<br data-filtered="filtered"><br data-filtered="filtered">  DragObject := TDragDockObjectEx.Create(Self);<br data-filtered="filtered"><br data-filtered="filtered">  DragObject.Brush.Color := clAqua; // this will display a red outline<br data-filtered="filtered"><br data-filtered="filtered">end;<br data-filtered="filtered">
5.Create a new class function called CreateDockForm that accepts a TColor, returns a TCustomForm and contains the following code.

1
class function TfrmDock.CreateDockForm(const aColor: TColor): TCustomForm;<br data-filtered="filtered"><br data-filtered="filtered">begin<br data-filtered="filtered"><br data-filtered="filtered">  result := TfrmDock.Create(Application);<br data-filtered="filtered"><br data-filtered="filtered">  result.Color := aColor;<br data-filtered="filtered"><br data-filtered="filtered">  result.Caption := ColorToString(aColor);<br data-filtered="filtered"><br data-filtered="filtered">  result.Show;<br data-filtered="filtered"><br data-filtered="filtered">end;<br data-filtered="filtered">

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
procedure TfrmMain.Button1Click(Sender: TObject);
 
var
 
  i: Integer;
 
begin
 
  // close all previously dockable forms before recreating
 
  for i := 0 to Screen.FormCount - 1 do
 
    if Screen.Forms[i] is TfrmDock then
 
      Screen.Forms[i].Close;
 
  // dock to the component called pDockLeft
 
  TfrmDock.CreateDockForm(clBlue).ManualDock(pDockLeft);
 
  // dock to the top on the pDockLeft panel
 
  TfrmDock.CreateDockForm(clGreen).ManualDock(pDockLeft, nil, alTop);
 
  // dock to the right on the pDockLeft panel
 
  TfrmDock.CreateDockForm(clRed).ManualDock(pDockLeft, nil, alRight);
 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
delphi数据库图片的存取【转】发布时间:2022-07-18
下一篇:
delphi实体类JSON数组TJsonSerializerDeserialize发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap