標籤:
http://www.cnblogs.com/jxsoft/archive/2011/08/25/2152872.html1 新手上路1.1 控制項簡介
Dock panels
Dock panels是建立停靠應用的最主要部分,是在應用內部的windows局部視窗,可以放置其他的VCL控制項。當一個Dock panels放在Form上後,它會自動漂浮在Form之上。如果需要停靠到表單中,需要使用TdxDockSite控制項,並且可以設定主題風格。
注意,當要對Dock panels控制項進行刪除、複製粘貼或者其他一些操作時,務必使用控制項的操作功能表來實現。
Dock panels之間可以互相停靠,停靠的結果有2種類型-tab containers 和side containers,例如,可以將side containers放到一個tab containers中。
Dock Sites
Dock Sites支援放置Dock panels,注意Dock Sites只能接受Dock panels控制項;
如果沒有Dock Sites上沒有控制項時,會有一個空白的矩形地區佔位,如果不想這樣,可以採用以下技巧:
l 用一個Dock Sites填充整個Form,然後在上面放上一個Dock panels;
l 如果將DockSites的autoSize屬性設為true,它的大小會自適用所接受的Dock Panel或者container;
Docking Manager
Docking Manager控制項可以集中控制所有或者部分的停靠控制項。注意,它不是必須的,如果在Application的任何表單上都沒有放置Docking Manager,docking controller會接管停靠控制項的管理。但是docking controller只提供預設設定,不允許改變停靠控制項的設定。一般情況下都會使用Docking Manager。
1.2 如何定製Dock Panels外觀
ExpressDocking提供4種預先設定好顯示風格,標準(類似於Delphi)、Visual Studio .Net、office和Windows Xp風格。為了在設計時就能指定風格,需要使用Docking Manager的ViewStyle和LookAndFeel屬性。注意LookAndFeel屬性設定只能在ViewStyle屬性設定為vsUseLookAndFeel時使用。
要指定一個dock panel的caption,使用Caption屬性,設定表徵圖使用ImageIndex屬性,當然之前要給docking manager提供一個imageList。
1.3 停靠的基本操作
如果要改變dock panel的位置,但是不想在經過dock site上方的時候自動嵌入,可以在拖動的時候按住CTRL。
停靠控制項的AllowDockClients屬性為接受的控制項停靠設定位置,AllowDock為停靠到其他控制項設定位置。設定AllowFloating為False,可以禁止停靠控制項漂浮,Dockable設定為False,則不允許拖動停靠。
1.4 建立一個Visual Studio .Net風格的介面
l 建立一個應用;
l 在表單上放置一個TdxDockSite控制項,並設定Align屬性為alClient;
l 在TdxDockSite上放置一個TdxDockPanel控制項,TdxDockPanel會自動充滿整個TdxDockSite的地區。設定ShowCaption屬性為False,隱藏面板標題列;
l 在TdxDockPanel上放置一個memo控制項,並設定Align為alClient;
l 設定dock panel的AllowDockClients屬性,將所有的選項為False,阻止其他dock panel的停靠;
l 將dock site的AllowDockClients屬性的dtTop選項設為False,將會阻止其他dock panel停靠到其上方;
l 至此,所有準備步驟已經就緒。現在可以在表單上建立一些dock panel,這些dock panel只能被拖放到表單的邊緣,除了上方。當一個dock panel停靠到表單的左邊,設定AutoHide屬性,將會自動加入一個side container控制項;
l 剩下的事情就要切入主題了,放置一個docking manager控制項,設定ViewStyle屬性為vsNET,整個應用的介面就會變成VS .NET風格了。
2 運行時的停靠控制項2.1 停靠規則
Dock panel 只能在dock site上該能改變大小。ExpressDocking提供2種停靠點類型:dock sites、layout sites和float sites。Dock sites 是放置在表單上,用來接受dock panel的停靠;Layout sites是當有停靠操作時,自動建立在dock site上,以提供更靈活的布局定製;Float sites是漂浮dock panel的載體;
當dock panel處於漂浮狀態,會自動建立Float sites,一旦dock panel停靠,Float site就會被銷毀;
Layout sites 也是自動建立的,在dock panel停靠後發生。Layout site不會佔據空間;
2.2 在運行時控制dock panels的停靠
Dock panel 提供DockTo, MakeFloating和UnDock方法來執行停靠操作。
MakeFloating是使dock panel離開Dock site而處於漂浮狀態;
UnDock類似於MakFloating,但是會隱藏Dock panel。這個方法很有用處,例如當一個dock panel停靠到另外一個dock panel形成side container,你需要知道目標dock panel是不是在一個tab container中,如果之前所有的dock panel都被UnDock了,那麼你就不必擔心擔心了。
例如將dock panel停靠到左邊:
dxDockPanel1.DockTo(dxDockSite1, dtLeft, 0);
例如將一個dock panel充滿表單的下方,另外一個dock panel放置未充滿地區的右側:
dxDockPanel2.DockTo(dxDockSite1, dtBottom, 0); //此步會自動建立一個LayoutDockSite來放置dxDockPanel2;
dxDockPanel3.DockTo(dxDockPanel2.LayoutDockSite, dtRight, 0); //在dxDockPanel2的LayoutDockSite上來布局新dock panel;
docking manager提供一些方法來儲存和載入布局,這些方法是SaveLayoutToIntFile, SaveLayoutToRegistry, SaveLayoutToStream, LoadLayoutFromIntFile,LoadLayoutFromRegistry, LoadLayoutFromStream
2.3 建立和管理Container Control
l 調用停靠控制項的DockTo方法就會自動一個建立容器;當UnDock發生後,會自動銷毀容器空間;
l 調用停靠控制項的MakeFloating方法會自動銷毀容器控制項;
l 調用容器的ActiveChildIndex來尋找當前活動dock panel;
l Dock Panel有個DockIndex屬性,決定了其在容器中的索引;
l 容器有Children,ChildCount, ValidChildren和ValidChildCount屬性,可以用來訪問容器的成員dock panel;
l Dock panel的ParentDockControl, TabContainer和SideContainer屬性可以用來訪問父停靠控制項;
例如下面的代碼示範:
// Delphi
var
ATabContainer: TdxTabContainerDockSite;
ASideContainer: TdxSideContainerDockSite;
begin
// create a side container by docking the second panel
// to the center of the first one
dxDockPanel2.DockTo(dxDockPanel1, dtClient, 1);
// obtaining the tab container created
ATabContainer := dxDockPanel1.TabContainer;
if ATabContainer = nil then Exit;
// adding the third panel to the tab container
dxDockPanel3.DockTo(ATabContainer, dtClient, 2);
// switching to the first panel (tab)
ATabContainer.ActiveChildIndex := dxDockPanel1.DockIndex;
// create a vertical side container
dxDockPanel4.DockTo(dxDockPanel5, dtTop, 0);
// obtain the side container created
ASideContainer := dxDockPanel4.SideContainer;
if ASideContainer = nil then Exit;
// expand the top panel within the side container
ASideContainer.ActiveChildIndex := dxDockPanel4.DockIndex;
// dock the side container to a site‘s right edge
ASideContainer.DockTo(dxDockSite1, dtRight, 0);
// dock the tab container to a site‘s bottom edge
ATabContainer.DockTo(dxDockSite1, dtBottom, 0);
end;
2.4 在運行時動態建立停靠控制項
停靠控制項依靠Visible屬性來設定是否顯示。當調用控制項的Close方法也會隱藏控制項,但要記住,需要將docking manager的doFreeOnClose選項禁用,否則,Close方法會銷毀控制項;另外一個隱藏控制項的方法是使用UnDock。調用Free也是銷毀控制項。
l 不必手工建立容器控制項,因為他們是伴隨停靠操作自動建立和銷毀的;
l 如果一個控制項隱藏,容器還會為它保留位置,當再次顯示時,還會出現在同樣的位置;
l 如果開啟自動隱藏特性,再設定Visible屬性為False會無效;因此在隱藏這類控制項前,最好先取消自動隱藏特性;
停靠控制項提供一些事件來響應這些操作:VisibleChanged, VisibleChaning, OnClose, OnCloseQuery;
l 顯示和隱藏停靠控制項的樣本
procedure TForm1. Button1Click(Sender: TObject);
begin
if dxDockPanel1.AutoHide and not dxDockPanel1.Visible then
begin
dxDockingController.BeginUpdate;
try
// make the panel‘s client area visible on screen
dxDockPanel1.Visible := True;
// hide the panel
dxDockPanel1.Visible := False;
finally
dxDockingController.EndUpdate;
end;
end
else
dxDockPanel1.Visible := not dxDockPanel1.Visible;
end;
l 動態建立停靠控制項
procedure TForm1.FormCreate(Sender: TObject);
begin
// specify the open dialog抯 filter
OpenDialog1.Filter := ‘*.bmp|*.bmp‘;
with dxDockingManager1 do
begin
// force dock controls to be destroyed when closed
Options := dxDockingManager1.Options + [doFreeOnClose];
// specify the default tabs position and
// the dock controls paint style
DefaultTabContainerSiteProperties.TabsPosition := tctpTop;
ViewStyle := vsNET;
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
APicture: TPicture;
APanel: TdxDockPanel;
AImage: TImage;
ALastIndex, I: Integer;
begin
if Key = VK_INSERT then
begin
// open the file and create the corresponding image object
if not OpenDialog1.Execute() then Exit;
APicture := TPicture.Create();
APicture.LoadFromFile(OpenDialog1.FileName);
// create a new panel that will hold the image
APanel := TdxDockPanel.Create(Self);
APanel.Caption := ExtractFileName(OpenDialog1.FileName);
// check whether the dock site already has docked controls
if dxDockSite1.ChildCount > 0 then
begin
// add the panel to the tab container
ALastIndex := dxDockSite1.Children[1].ChildCount;
APanel.DockTo(dxDockSite1.Children[1], dtClient, ALastIndex + 1);
end
else
// dock the panel to the dock site
APanel.DockTo(dxDockSite1, dtClient, 0);
// create an image control and place it on the panel
AImage := TImage.Create(Self);
AImage.Parent := APanel;
AImage.Align := alClient;
AImage.Center := True;
AImage.Picture := APicture;
end;
// delete all panels if the DELETE key has been pressed
if Key = VK_DELETE then
begin
for I := 0 to dxDockingController.DockControlCount - 1 do
begin
if dxDockingController.DockControls[I] is TdxDockPanel then
dxDockingController.DockControls[I].Close;
end;
end;
end;
轉:ExpressBars中的停靠控制項使用