Tpanel처럼 동작하는 TCustomControl을 만드는 방법은 무엇입니까?
-
17-09-2020 - |
문제
Tpanel처럼 동작하는 TCustomControl을 어떻게 생성하나요?예를 들어 레이블, 이미지 등과 같은 구성 요소를 놓을 수 있는 MyCustomComponent입니다.
해결책
비결은 TCustomPanel에 있는 다음 코드입니다.
constructor TCustomPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls {, ... } ];
//...
end;
더 많은 VCL 컨트롤이 있습니다. csAcceptsControls
그들의 ControlStyle
재산.
자신의 컨트롤에서 이 작업을 수행하고 싶지만 이러한 VCL 컨트롤에서 파생되지 않는 경우 다음과 같이 해야 합니다.
- Create 생성자를 재정의합니다.
- 추가하다
csAcceptsControls
~로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.
--제로엔
제휴하지 않습니다 StackOverflow