How to disable child controls at design-time?

2019-05-15 03:14发布

I have my own control, derived from TCustomPanel. It has a child (TEdit) on it.

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;

When I click on a child control at design-time, it acts as the run-time TEdit, capturing focus.

How to completely disable child controls at design time?

I want them to stop answering mouse/keyboard messages. When I click on them at design-time, I want the parent control to be selected and dragged.

1条回答
干净又极端
2楼-- · 2019-05-15 03:40

Use Self as the owner in the edit constructor to make your edit sub-component of your panel and to let the panel handle its destruction. And call SetSubComponent function with the IsSubComponent paremeter set to True for each sub-component to see your panel control as one in the structure pane.

constructor TMyControl.Create(AOwner: TComponent);
begin
  ...
  FEditor := TEdit.Create(Self);
  FEditor.SetSubComponent(True);
  FEditor.Parent := Self;
  ...
end;
查看更多
登录 后发表回答