开发者

how to create a TCustomControl that behaves like Tpanel?

开发者 https://www.devze.com 2023-01-08 01:44 出处:网络
how do I create a TCustomControl that will behave like Tpanel? eg My开发者_运维百科CustomComponent, that I can drop components in like labels, images etc.The trick is this piece of code in TCustomPane

how do I create a TCustomControl that will behave like Tpanel? eg My开发者_运维百科CustomComponent, that I can drop components in like labels, images etc.


The trick is this piece of code in TCustomPanel:

constructor TCustomPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := [csAcceptsControls {, ... } ];
//...
end;

There are many more VCL controls you can descend from that have csAcceptsControls in their ControlStyle property.

If you want to do this in your own controls, but do not descend from such a VCL control, then you should do something like this:

  1. Override the Create constructor
  2. Add csAcceptsControls to the ControlStyle property

Like this sample code:

//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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号