代码之家  ›  专栏  ›  技术社区  ›  jpfollenius Rob Kennedy

如何将按钮动态添加到TCategoryPanelGroup?

  •  0
  • jpfollenius Rob Kennedy  · 技术社区  · 15 年前

    有没有人体验过Delphi2009的TCategoryPanelGroup组件,特别是在类别面板中动态添加按钮方面?

    我不能让它正常工作。按钮未出现或对齐方式已拧紧。我要做的基本概述:

    procedure AddButton (const Caption, Group : String);
    const 
      ButtonSize = 55;
      Border = 10;
    var
      CategoryPanel : TCategoryPanel;
      Button : TButton;       
    begin
      CategoryPanel := FindCategoryPanel (CategoryPanelGroup, Group);
      CategoryPanel.Height := CategoryPanel.Height + ButtonSize + Border;
      Button := TButton.Create (CategoryPanel);
      Button.Parent := CategoryPanel;
      Button.Width := ButtonSize;
      Button.Height := ButtonSize;
      Button.Left := 27;
      Button.Top := CategoryPanel.ClientHeight - Border - ButtonSize;
    end;
    

    有什么暗示吗?

    2 回复  |  直到 15 年前
        1
  •  0
  •   Toon Krijthe    15 年前

    到底是什么问题?按钮显示在所需位置。

    您确定要不带文本的方形按钮吗?

    使用:

    Button.Left := 0;
    Button.Width := CategoryPanel.ClientWidth - 2;
    

    使其与面板减去像素偏移量时的宽度完全相同。

    使用:

    button.width:=categorypanel.clientwidth; 按钮。左:=-1;

    创建最大宽度。它有一个1像素的偏移量。

    我在用2010年的时间来公平。

        2
  •  0
  •   jpfollenius Rob Kennedy    15 年前

    问题是我指定顶坐标的方式。

    我把它改成了

    ButtonCount := CategoryPanel.ComponentCount - 2;
    Button.Top := Border + ButtonCount * (ButtonSize + Border);
    CategoryPanel.ClientHeight := Border + (ButtonCount+1) * (ButtonSize + Border);
    

    它起作用了。

    不知道问题的确切原因。