问题
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