如何制作不能包含其他控件的控件?

Mas*_*ler 4 delphi component-design

我正在设计一个自定义控件,每次我在表单设计器中突出显示它,然后从控件选项板中选择另一个控件,新的控件最终在我的控件内,就像它是TPanel或TGroupBox一样.这不是我想要的,所以我怎么能阻止它发生?

mgh*_*hie 14

您需要csAcceptsControlsControlStyle属性中删除该标志,理想情况下直接在构造函数中:

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