2011-11-26 48 views

回答

6

一看T(自定义)CategoryPanel的源揭示了一个方法DrawCollapsedPanel。它无条件地绘制分隔符。从DrawHeader调用DrawCollapsedPanel,检查唯一条件是面板是否折叠。

更重要的是,DrawCollapsedPanel是虚拟的,所以你可以创建自己的后代或者使用拦截器类:

TCategoryPanel = class(ExtCtrls.TCategoryPanel) 
protected 
    procedure DrawCollapsedPanel(ACanvas: TCanvas); override; 
    function GetCollapsedHeight: Integer; override; 
end; 

如果你把它放进一个单独的单元,所有你需要做的就是包括它在ExtCtrls单元之后,你想要一个你自己的行为的类别面板。

为了取悦大卫:-)

procedure TCategoryPanel.DrawCollapsedPanel(ACanvas: TCanvas); 
begin 
    // Don't call inherited, we do not want the default separator. 
    // And don't draw anything you don't want. 
end; 

,我们需要重写GetCollapsedHeight为好,因为它确定任何你想要的标题下绘制了折叠可用于室内:

function TCategoryPanel.GetCollapsedHeight: Integer; 
begin 
    // As we don't want anything under here, 
    // don't call inherited and just return the HeaderHeight. 
    // (Instead of HeaderHeight + 6; 
    Result := HeaderHeight; 
end; 

截图:

enter image description here

+0

什么阿布t执行重写的方法吗? –

+0

@David:在绘画方面,我不是专家,所以我想把它作为读者的练习。我会说,嗯,空?因为他不想要分隔符......尽管他将不得不重写GetCollapsedHeight以及确定要在折叠状态下的标题下绘制任何内容的高度。 –

+1

@David:为你添加了一些实现:-) –