How to disable child controls at design-time?

跟風遠走 提交于 2019-12-22 10:55:44

问题


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:


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;


来源:https://stackoverflow.com/questions/11209523/how-to-disable-child-controls-at-design-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!