2013-05-21 22 views
2

我有一個應用程序附帶一個邊欄(TPanel - >alRight),其中使用了一個CategoryPanel(alClient)。該CategoryPanel恰好有2個未對齊的組。我想分享這兩個組的邊界,以50/50的比例填滿整個面板空間。不幸的是,CategoryGroups在設計時不支持對齊,這迫使我每次運行我的應用程序時都要測試它。我試圖設置每個CategoryGroup的高度爲面板的一半,但它顯示滾動條。 (請參見圖2)我該如何製作兩個控件,每個都佔據父母面積的一半?

如何正確對齊/以50/50的比例分享邊界?

Image1 Image2

+0

當類別組關閉時,您希望發生什麼? –

+0

如果他們崩潰了,什麼都不應該發生,大小隻是保持不變。 –

回答

5

根據您的意見,您要運行該代碼:

procedure TForm1.UpdateGroupHeights; 
begin 
    if not CategoryPanel1.Collapsed then 
    CategoryPanel1.Height := CategoryPanelGroup1.ClientHeight div 2; 
    if not CategoryPanel2.Collapsed then 
    CategoryPanel2.Height := CategoryPanelGroup1.ClientHeight - 
     CategoryPanelGroup1.ClientHeight div 2; 
end; 

每當有什麼變化,你想影響你組的佈局。所以我認爲你需要從以下事件中調用這個函數:

  • 該事件的形式爲OnCreate
  • OnResize事件TCategoryPanelGroup
  • OnCollapseOnExpand事件的兩個類別面板。

雖然一個面板摺疊而另一個面板展開,但看起來有點奇怪。我個人會重新調整代碼以填充所有可用空間。

if not CategoryPanel1.Collapsed then 
    ;//nothing to do 
if CategoryPanel1.Collapsed and not CategoryPanel2.Collapsed then 
    CategoryPanel2.Height := CategoryPanelGroup1.ClientHeight-CategoryPanel1.Height; 
if not CategoryPanel1.Collapsed and CategoryPanel2.Collapsed then 
    CategoryPanel1.Height := CategoryPanelGroup1.ClientHeight-CategoryPanel2.Height; 
if not CategoryPanel1.Collapsed and not CategoryPanel2.Collapsed then 
begin 
    CategoryPanel1.Height := CategoryPanelGroup1.ClientHeight div 2; 
    CategoryPanel2.Height := CategoryPanelGroup1.ClientHeight-CategoryPanel1.Height; 
end; 
+0

完全忘了ClientHeight!非常感謝你。 –

相關問題