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 对象数组。

示例

下面的代码示例演示如何在派生自 ToolboxItemCreateComponentsCore类中对自定义工具箱项实现使用 方法。 此代码示例是为 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 会将新组件添加到设计器。

适用于