问题描述
我有自己的控件,该控件来自 TCustomPanel
。它上面有一个孩子( TEdit
)。
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;
在设计时单击子控件时,它充当运行时 TEdit
来吸引焦点。
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.
推荐答案
使用 Self
作为编辑构造函数的所有者,以 make 您的面板的编辑子组件,并让面板处理其破坏。然后调用函数,并将每个子组件的 IsSubComponent
参数设置为True,以将面板控件在结构窗格中显示为一个。
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;
这篇关于如何在设计时禁用子控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!