MenuDesigner.Initialize(IComponent) 方法

定義

準備設計工具,以檢視、編輯和設計關聯控制項。

public:
 override void Initialize(System::ComponentModel::IComponent ^ component);
public override void Initialize (System.ComponentModel.IComponent component);
override this.Initialize : System.ComponentModel.IComponent -> unit
Public Overrides Sub Initialize (component As IComponent)

參數

component
IComponent

Menu,實作 IComponent 介面。

例外狀況

「元件」不是 Menu 或屬於 Menu 的衍生類別。

範例

下列程式代碼範例示範如何在繼承自 MenuDesigner 類別的類別中覆寫 Initialize 方法。 覆寫的方法會變更在設計時間衍生自 Menu 類別的控件行為。 如果相關聯的控件不是 MyMenu 物件,則此範例會擲回ArgumentException例外狀況。

public override void Initialize(IComponent component)
{
    // Ensure that only a MyMenu can be created in this designer.
    if (!(component is MyMenu))
        throw new ArgumentException(
            "The component is not a MyMenu control.");
    
    base.Initialize(component);
} // Initialize
Public Overrides Sub Initialize(ByVal component As IComponent)

    ' Ensure that only a MyMenu can be created in this designer. 
    If Not TypeOf component Is MyMenu Then
        Throw New ArgumentException( _
            "The component is not a MyMenu control.")
    End If

    MyBase.Initialize(component)

End Sub

備註

可視化設計工具在準備好使用設計工具來轉譯Menu控件時,會呼叫 Initialize 方法。 方法 Initialize 及其基底方法會設定屬性,並設定設計工具作業所需的事件。

參數 componentMenu 與此設計工具或該控件複本相關聯的控件。

適用於

另請參閱