让我控制的组件在IDE中成为我控制的孩子 [英] Let components dropped on my control in the IDE become children of my control

查看:143
本文介绍了让我控制的组件在IDE中成为我控制的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个后代 TWinControl (实际上它只是现在),我将其注册为IDE中的一个组件:

I have a descendant of TWinControl (in fact it is just that for now) and I registered it as a component in the IDE:

type
  TGroupPanel = class(TWinControl);

但是当我删除其他组件时,它们附加到表单而不是我的控制。换句话说,我希望我的自定义控件的行为就像一个 TPanel ,使其上的组件成为它的孩子。

But when I drop other components on it, they attach to the form instead of to my control. In other words, I want my custom control to behave like a TPanel so that components dropped on it become its children.

如果我在运行时创建组件并将其手动分配给我的控件,就像下面的代码一样,它的工作原理是:

If I create the components at runtime and assign them manually to my control, like in the code below, then it works:

  TForm1 = class(TForm)
    Group: TGroupPanel;
    procedure FormCreate(Sender: TObject);
  private
    Panel: TPanel;
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Panel := TPanel.Create(Group);
  Panel.Parent := Group;
  Panel.Align := alClient;
end;

所以,我应该怎么做才能将组件放在 TWinControl 在设计时成为该控件的孩子?

So, what should I do to get components dropped on a TWinControl at design time become children of that control?

(我想要做的是做一个特殊的控制来组合其他组件,所以我可以将它们对齐并将它们放在一起,当然我可以用一个普通的面板来做,但是我想用一个没有绘制任何东西的轻量级控件来实现,而在 TWinControl 我找到解决方案。)

(What I am trying to do is to make a special control to group other components on, so I can align and position them together. Of course, I can do that with a normal panel, but I want to do this with a lightweight control that does not paint anything, and in TWinControl I found the solution.)

推荐答案

设置 csAcceptControls code> ControlStyle

Set csAcceptControls flag for ControlStyle.

constructor TGroupPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle + [csAcceptsControls];
end;

这篇关于让我控制的组件在IDE中成为我控制的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆