語言

ToolboxItem.CreateComponentsCore 方法

定義

當工具箱項目被呼叫時,會建立一個元件或元件陣列。

多載

名稱 Description
CreateComponentsCore(IDesignerHost)

當工具箱項目被呼叫時,會建立一個元件或元件陣列。

CreateComponentsCore(IDesignerHost, IDictionary)

當工具箱項目被呼叫時,會建立一個元件陣列。

CreateComponentsCore(IDesignerHost)

來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs

當工具箱項目被呼叫時,會建立一個元件或元件陣列。

protected:
 virtual cli::array <System::ComponentModel::IComponent ^> ^ CreateComponentsCore(System::ComponentModel::Design::IDesignerHost ^ host);
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host);
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host);
abstract member CreateComponentsCore : System.ComponentModel.Design.IDesignerHost -> System.ComponentModel.IComponent[]
override this.CreateComponentsCore : System.ComponentModel.Design.IDesignerHost -> System.ComponentModel.IComponent[]
Protected Overridable Function CreateComponentsCore (host As IDesignerHost) As IComponent()

參數

host
IDesignerHost

然後 IDesignerHost 來主機工具箱的物品。

傳回

一組已建立 IComponent 的物件。

備註

若 host 不是 null,則 CreateComponentsCore 該方法將新元件加入設計器。

給繼承者的注意事項

你可以覆寫 CreateComponentsCore(IDesignerHost) 返工具箱物品所產生的元件的方法。

另請參閱

適用於

CreateComponentsCore(IDesignerHost, IDictionary)

來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs
來源:
ToolboxItem.cs

當工具箱項目被呼叫時,會建立一個元件陣列。

protected:
 virtual cli::array <System::ComponentModel::IComponent ^> ^ CreateComponentsCore(System::ComponentModel::Design::IDesignerHost ^ host, System::Collections::IDictionary ^ defaultValues);
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host, System.Collections.IDictionary defaultValues);
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host, System.Collections.IDictionary? defaultValues);
abstract member CreateComponentsCore : System.ComponentModel.Design.IDesignerHost * System.Collections.IDictionary -> System.ComponentModel.IComponent[]
override this.CreateComponentsCore : System.ComponentModel.Design.IDesignerHost * System.Collections.IDictionary -> System.ComponentModel.IComponent[]
Protected Overridable Function CreateComponentsCore (host As IDesignerHost, defaultValues As IDictionary) As IComponent()

參數

host
IDesignerHost

設計器主機用於建立元件。

defaultValues
IDictionary

一個屬性名稱/值的字典,預設值對,用來初始化元件。

傳回

一組已建立 IComponent 的物件。

範例

以下程式碼範例展示了該方法在自訂工具箱項目實作中衍生的CreateComponentsCore類別中的應用ToolboxItem。 此程式碼範例是本類別更大範例 ToolboxItem 的一部分。

protected override IComponent[] CreateComponentsCore(
    System.ComponentModel.Design.IDesignerHost host,
    System.Collections.IDictionary defaultValues)
{
    // Get the string we want to fill in the custom
    // user control.  If the user cancels out of the dialog,
    // return null or an empty array to signify that the 
    // tool creation was canceled.
    using (ToolboxItemDialog d = new())
    {
        if (d.ShowDialog() == DialogResult.OK)
        {
            string text = d.CreationText;

            IComponent[] comps =
                base.CreateComponentsCore(host, defaultValues);
            // comps will have a single component: our data type.
            ((UserControl1)comps[0]).LabelText = text;
            return comps;
        }
        else
        {
            return null;
        }
    }
}
Protected Overrides Function CreateComponentsCore( _
    ByVal host As System.ComponentModel.Design.IDesignerHost, _
    ByVal defaultValues As System.Collections.IDictionary) _
    As IComponent()
    ' Get the string we want to fill in the custom
    ' user control.  If the user cancels out of the dialog,
    ' return null or an empty array to signify that the 
    ' tool creation was canceled.
    Using d As New ToolboxItemDialog()
        If d.ShowDialog() = DialogResult.OK Then
            Dim [text] As String = d.CreationText
            Dim comps As IComponent() = _
                MyBase.CreateComponentsCore(host, defaultValues)
            ' comps will have a single component: our data type.
            CType(comps(0), UserControl1).LabelText = [text]
            Return comps
        Else
            Return Nothing
        End If
    End Using
End Function

備註

若 host 不是 null,則 CreateComponentsCore 該方法將新元件加入設計器。

適用於