下面我來講一下兩個窗體怎樣停靠成PageControl樣式。
首先創建一個窗體,叫TabHost,在它上面放一個PageControl,Align屬性設成alClIEnt,讓它占滿整個TabHost,別忘了把PageControl的DockSite屬性設成True.
然後我們依次加入代碼:
procedure TDockableForm.FormDockOver(Sender: TObject;
Source: TDragDockObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
var
ARect: TRect;
begin
Accept := Source.Control is TDockableForm;
if Accept then
begin
ARect.TopLeft := ClientToScreen(ClIEntRect.TopLeft);
ARect.BottomRight := ClientToScreen(ClIEntRect.BottomRight);
Source.DockRect := ARect;
end;
和
procedure TDockableForm.CMDockClient(var Message: TCMDockClIEnt);
var
Host: TForm;
begin
if Message.DockSource.Control is TDockableForm then
begin
Host := TTabHost.Create(Application);
Host.BoundsRect := Self.BoundsRect;
Self.ManualDock(TTabHost(Host).PageControl1, nil, alClIEnt);
Message.DockSource.Control.ManualDock(TTabHost(Host).PageControl1, nil, alClIEnt);
Host.Visible := True;
End;
End;