2010-07-19 5 views
1

Tpanel처럼 동작하는 TCustomControl을 어떻게 만듭니 까?Tpanel처럼 동작하는 TCustomControl을 만드는 방법은 무엇입니까?

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

많은 더 VCL은 당신이 csAcceptsControls이 그에서 내려갈 수있는 컨트롤이 있습니다 내가 좋아하는 상표의 구성 요소를 제거 할 수 있습니다 예를 들어 MyCustomComponent, 이미지 등

답변

7

비결은 TCustomPanel 코드의 조각 그들의 ControlStyle 속성.

  • 받는 csAcceptsControls 추가

    1. 재정의 생성자 만들기 : 당신이 당신의 자신의 컨트롤에이 작업을 수행 할 수 있지만, 이러한 VCL 컨트롤에서 내려하지 않는 경우

      은 다음과 같이해야합니다 ControlStyle이 샘플 코드와 마찬가지로 재산

    :

    //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. 
    

    - 제로

  • 관련 문제