我如何创建一个行为像Tpanel的TCustomControl?例如MyCustomComponent,我可以把标签,图片等组件放进去。
发布于 2010-07-19 14:54:19
诀窍是TCustomPanel中的这段代码:
constructor TCustomPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls {, ... } ];
//...
end;您可以从许多在ControlStyle属性中具有csAcceptsControls的VCL控件派生。
如果您想在自己的控件中执行此操作,但不是从这样的VCL控件派生出来的,那么您应该这样做:
ControlStyle属性的Create constructor
csAcceptsControls例如下面的示例代码:
//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
https://stackoverflow.com/questions/3278752
复制相似问题