2011-11-26 47 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:爲你添加了一些實現:-) –