如何删除或更改"类别面板"控件中的"水平分隔符"?

Mic*_*nny 1 delphi panel separator delphi-2010

我一直在使用Delphi 2010中的Category Panel Control.我已经能够修改颜色并让它们以我喜欢的方式工作.但是,每个面板标题之间都有一个银色的"水平分隔符"(我不知道还有什么可以称之为).

如何更改此"水平分隔符"的外观或将其全部删除?

在此输入图像描述

Mar*_*ema 6

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

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

TCategoryPanel = class(ExtCtrls.TCategoryPanel)
protected
   procedure DrawCollapsedPanel(ACanvas: TCanvas); override;
   function GetCollapsedHeight: Integer; override;
end;
Run Code Online (Sandbox Code Playgroud)

如果你将它放在一个单独的单元中,那么你需要做的就是在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;
Run Code Online (Sandbox Code Playgroud)

我们还需要覆盖GetCollapsedHeight,因为它确定了在折叠状态下Header下要绘制的任何内容的可用空间:

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;
Run Code Online (Sandbox Code Playgroud)

截图:

在此输入图像描述