2012-06-26 23 views
3

我有我自己的控制,來自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,捕捉的焦點。

如何在設計時完全禁用子控件?

我希望他們停止回覆鼠標/鍵盤消息。當我在設計時點擊它們時,我想要選擇並拖動父控件。

+0

它可以被拖入它的父級?如果不是,那不是設計師給你帶來麻煩。嘗試在設計時禁用編輯。 – GolezTrol

+0

@GolezTrol是的,當孩子控制禁用,everythign正常工作。但是,外觀不同(變灰)。 – Andrew

回答

5

使用Self作爲編輯構造函數中的所有者到使您的面板的編輯子組件並讓面板處理其銷燬。並且將SetSubComponent函數的IsSubComponent參數設置爲True,以使每個子組件在結構窗格中看到您的面板控件。

constructor TMyControl.Create(AOwner: TComponent); 
begin 
    ... 
    FEditor := TEdit.Create(Self); 
    FEditor.SetSubComponent(True); 
    FEditor.Parent := Self; 
    ... 
end; 
+0

是的,謝謝!然而,它甚至沒有'SetSubComponent(True);',也許它沒有必要? – Andrew

+0

是的,但[[SetSubComponent]](http://docwiki.embarcadero.com/Libraries/en/System.Classes.TComponent.SetSubComponent)會導致您將面板始終視爲「結構'窗格。討論過['here'](http://stackoverflow.com/q/9479872/960757)。 – TLama

+0

現在我明白了 – Andrew

相關問題