Delphi 我如何制作一个可以';不包含其他控件?

Delphi 我如何制作一个可以';不包含其他控件?,delphi,component-design,Delphi,Component Design,我正在设计一个自定义控件,每次我在窗体设计器中高亮显示它,然后从控件调色板中选择另一个控件时,新控件就会出现在我的控件中,就像它是TPanel或TGroupBox一样。这不是我想要的,因此如何防止它发生?您需要从ControlStyle属性中删除csAcceptsControls标志,最好直接在构造函数中: constructor TMyComponent.Create(AOwner: TComponent); begin inherited Create(AOwner); Contro

我正在设计一个自定义控件,每次我在窗体设计器中高亮显示它,然后从控件调色板中选择另一个控件时,新控件就会出现在我的控件中,就像它是TPanel或TGroupBox一样。这不是我想要的,因此如何防止它发生?

您需要从
ControlStyle
属性中删除
csAcceptsControls
标志,最好直接在构造函数中:

constructor TMyComponent.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csAcceptsControls];
  // more initialization stuff ...
end;