2010-07-19 58 views

回答

7

關鍵是這段代碼在TCustomPanel:

constructor TCustomPanel.Create(AOwner: TComponent); 
begin 
    inherited Create(AOwner); 
    ControlStyle := [csAcceptsControls {, ... } ]; 
//... 
end; 

還有更多的VCL控件,你可以從下降有csAcceptsControls在他們的ControlStyle屬性。

如果你想這樣做,在你自己的控件,但不從這樣的VCL控制下降,那麼你應該做這樣的事情:

  1. 覆蓋創建構造
  2. 添加csAcceptsControlsControlStyle財產

像此示例代碼:

//MMWIN:MEMBERSCOPY 
unit _MM_Copy_Buffer_; 

interface 

type 
    TMyCustomControl = class(TSomeControl) 
    public 
    constructor Create(AOwner: TComponent); override; 
    end; 


implementation 

{ TMyCustomControl } 

constructor TMyCustomControl.Create(AOwner: TComponent); 
begin 
    inherited Create(AOwner); 
    ControlStyle := ControlStyle + [csAcceptsControls {, ...} ]; 
//... 
end; 


end. 

- jeroen

相關問題