如何在设计时禁用子控件?

时间:2012-06-26 14:23:54

标签: delphi controls design-time

我有自己的控制权,来自TCustomPanel。它上面有一个孩子(TEdit)。

type
  TMyControl = class(TCustomPanel)
  private
    FEditor: TEdit;
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy(); override;
  end;

  constructor TMyControl.Create(AOwner: TComponent);
  begin
    FEditor := TEdit.Create(nil);
    FEditor.Parent := Self;
  end;

  destructor TMyControl.Destroy(); 
  begin
    FEditor.Free();
  end;

当我在设计时单击子控件时,它充当运行时TEdit,捕获焦点。

如何在设计时完全禁用子控件?

我希望他们停止回答鼠标/键盘消息。当我在设计时点击它们时,我希望选择并拖动父控件。

1 个答案:

答案 0 :(得分:6)

使用Self作为编辑构造函数中的所有者,制作面板的编辑子组件,并让面板处理其销毁。并调用SetSubComponent函数,并为每个子组件将IsSubComponent参数设置为True,以将您的面板控件视为结构窗格中的一个。

constructor TMyControl.Create(AOwner: TComponent);
begin
  ...
  FEditor := TEdit.Create(Self);
  FEditor.SetSubComponent(True);
  FEditor.Parent := Self;
  ...
end;
相关问题