Delphi 如何使两个控件各自占据其父控件的一半';s区?

Delphi 如何使两个控件各自占据其父控件的一半';s区?,delphi,delphi-xe,vcl,Delphi,Delphi Xe,Vcl,我有一个应用程序,它附带了一个侧栏(TPanel-->OK),其中使用了一个CategoryPanel(alClient)。该类别面板正好有两个不对齐的组。我想分享这两组的边界,这样它将以50/50的比例填满整个面板空间。不幸的是,CategoryGroup不支持designtime中的对齐,这迫使我每次要测试应用程序时都要运行它。我试图将每个CategoryGroup的高度设置为面板的一半,但它会显示滚动条。(见图2) 如何以50/50的比例正确对齐/共享边界 根据您的评论,您希望运行以下代

我有一个应用程序,它附带了一个侧栏(
TPanel
-->
OK
),其中使用了一个CategoryPanel(
alClient
)。该类别面板正好有两个不对齐的组。我想分享这两组的边界,这样它将以50/50的比例填满整个面板空间。不幸的是,CategoryGroup不支持designtime中的对齐,这迫使我每次要测试应用程序时都要运行它。我试图将每个CategoryGroup的高度设置为面板的一半,但它会显示滚动条。(见图2)

如何以50/50的比例正确对齐/共享边界


根据您的评论,您希望运行以下代码:

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
    事件
  • TCategoryPanelGroup
    OnResize
    事件
  • 两个类别面板的
    OnCollapse
    OnExpand
    事件
当一个面板折叠,另一个面板展开时,这看起来有点奇怪。就个人而言,我会重新调整代码以填充所有可用空间

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;

当类别组关闭时,您希望发生什么?如果它们被折叠,则不会发生任何事情,大小保持不变。完全忘记了ClientHeight!非常感谢你。