1
如何創建一個TCustomControl,其行爲與Tpanel類似?例如MyCustomComponent,我可以像標籤組件拖放,圖像等如何創建一個類似Tpanel的TCustomControl?
如何創建一個TCustomControl,其行爲與Tpanel類似?例如MyCustomComponent,我可以像標籤組件拖放,圖像等如何創建一個類似Tpanel的TCustomControl?
關鍵是這段代碼在TCustomPanel:
constructor TCustomPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls {, ... } ];
//...
end;
還有更多的VCL控件,你可以從下降有csAcceptsControls
在他們的ControlStyle
屬性。
如果你想這樣做,在你自己的控件,但不從這樣的VCL控制下降,那麼你應該做這樣的事情:
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.
- jeroen