Search code examples
delphidelphi-2010panelseparator

How can I remove the or change the "horizontal separator" in a Category Panel control?


I've been playing around with the Category Panel Control inside Delphi 2010. I've been able to modify the colors and get them working they way I'd like. However, there's a silver colored "horizontal separator" (I don't know what else to call it) between each panel heading.

How can I change the appearance of this "horizontal separator" or remove it all together?

enter image description here


Solution

  • A look at the source of T(Custom)CategoryPanel reveals a method DrawCollapsedPanel. It unconditionally draws the separator. DrawCollapsedPanel is called from DrawHeader and the only condition checked is whether the panel is collapsed.

    More importantly though, DrawCollapsedPanel is virtual, so you can either create your own descendant or use an interceptor class:

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

    If you put this in a separate unit, all you need to do then is include it AFTER the ExtCtrls unit wherever you want a category panel with your own behaviour.

    To please David :-)

    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;
    

    and we need to override GetCollapsedHeight as well, as that determines the room available for whatever you want to draw under the Header in a collapsed state:

    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;
    

    Screenshot:

    enter image description here