在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
源地址: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
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.
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:
Name the new form frmDock and save the unit as DockForm. In the code editor for this unit do the following.
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
procedure TfrmDock.FormStartDock(Sender: TObject; var DragObject:
class function TfrmDock.CreateDockForm(const aColor: TColor): TCustomForm; 6.Finally modify the following properties on the dock form
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. 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); // dock directly to the DockTabSet TfrmDock.CreateDockForm(clWhite).ManualDock(DockTabSet1); end; The remaining code is required to get the docking behavior to play nice amongst each other.
1.Create an OnDockDrop event for the pDockLeft panel and add the following code
pDockLeft.Width := Source.Control.Width; The OnDockDrop code also makes sure that the splitter is visible when a form is being docked and that it is in the correct position.
procedure TfrmMain.pDockLeftDockDrop(Sender: TObject; Source: TDragDockObject; X, Y: Integer); begin if pDockLeft.Width = 0 then pDockLeft.Width := 150; Splitter1.Visible := True; Splitter1.Left := pDockLeft.Width; end; 2.Create an OnUndock event for the pDockLeft panel and add the following code
procedure TfrmMain.pDockLeftUnDock(Sender: TObject; Client: TControl; NewTarget: TWinControl; var Allow: Boolean); begin if pDockLeft.DockClientCount = 1 then begin pDockLeft.Width := 0; Splitter1.Visible := False; end; end; The DockOver event is the event responsible for drawing the forms outline at the dock site.
procedure TfrmMain.pDockLeftDockOver(Sender: TObject; Source: TDragDockObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var lRect: TRect; begin Accept := Source.Control is TfrmDock; if Accept then begin lRect.TopLeft := pDockLeft.ClientToScreen(Point(0, 0)); lRect.BottomRight := pDockLeft.ClientToScreen(Point(150, pDockLeft.Height)); Source.DockRect := lRect; end; end;
procedure TfrmMain.DockTabSet1DockDrop(Sender: TObject; Source: TDragDockObject; X, Y: Integer); The DockTabSet1 component should only be visible if there is a control docked to it.
procedure TfrmMain.DockTabSet1TabRemoved(Sender: TObject); begin DockTabSet1.Visible := DockTabSet1.Tabs.Count > 0; end;
More action shots Application appearance on startup
Tab selected. Note you can click on the pin button to pin the green form to the docksite or click on the cross to close the form. To not do anything, click in the memo to change the focus away from the green form to hide it.
Unfortunately there is a bug in the VCL.NET implementation of the TDockTabSet component. It is currently logged in QualityCentral and hopefully it will be addressed in the next major Delphi release.
Report No: 24640 ( RAID: 238759 ) Status: Open
The bug cannot be fixed in an update as it requires an interface change to the TDockTabSet class. If you wish to fix the bug yourself you can use the following workaround:
Move the DoAddDockClient method from strict private to protected and override it. previously... TDockTabSet = class(TTabSet)should become... TDockTabSet = class(TTabSet) You also have to take the necessary steps to ensure that the modified unit is compiled into your assembly as well.
An alternate approach might be:
procedure Register;
Closing comments With the help of the TDockTabSet component you can now create more advanced user interfaces with dockable windows which is sure to annoy most users. With a lot more hair pulling and sleepless nights, you can use the code in this article as a basis to create your our docking framework. I've done this as part for my QualityCentral windows client I created.
While doing so, don't forget to add any issues or enhancements to QualityCentral. Source Download
You can download the source to this article from Code Central: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论