如何创建一个表现像TPanel的TcustomControl?
-
17-09-2020 - |
题
如何创建一个与tpanel的tcustomcontrol?例如mycustomcomponent,我可以删除类似标签,图像等的组件。
解决方案
技巧是Tcustompanel中的这段代码:
constructor TCustomPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls {, ... } ];
//...
end;
.
有更多的VCL控件您可以从其csAcceptsControls
属性中下降到具有生成的。
如果您想在自己的控件中执行此操作,但不要从这样的vcl控件下降,那么您应该这样做:
- 覆盖Create构造函数
- 为
ControlStyle
属性添加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
不隶属于 StackOverflow