共用方式為


ToolboxItem.CreateComponentsCore 方法

定義

建立元件或叫用工具箱項目時要使用之元件的陣列。

多載

CreateComponentsCore(IDesignerHost)

建立元件或叫用工具箱項目時要使用之元件的陣列。

CreateComponentsCore(IDesignerHost, IDictionary)

在叫用工具箱項目時建立元件陣列。

CreateComponentsCore(IDesignerHost)

建立元件或叫用工具箱項目時要使用之元件的陣列。

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)

在叫用工具箱項目時建立元件陣列。

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 ToolboxItemDialog())
    {
        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 會將新的元件新增至設計工具。

適用於