Upraviť

Zdieľať cez


ToolboxItem.CreateComponentsCore Method

Definition

Creates a component or an array of components when the toolbox item is invoked.

Overloads

CreateComponentsCore(IDesignerHost)

Creates a component or an array of components when the toolbox item is invoked.

CreateComponentsCore(IDesignerHost, IDictionary)

Creates an array of components when the toolbox item is invoked.

CreateComponentsCore(IDesignerHost)

Creates a component or an array of components when the toolbox item is invoked.

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()

Parameters

host
IDesignerHost

The IDesignerHost to host the toolbox item.

Returns

An array of created IComponent objects.

Remarks

If host is not null, the CreateComponentsCore method adds the new components to the designer.

Notes to Inheritors

You can override the CreateComponentsCore(IDesignerHost) method to return the component or components that a toolbox item creates.

See also

Applies to

CreateComponentsCore(IDesignerHost, IDictionary)

Creates an array of components when the toolbox item is invoked.

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()

Parameters

host
IDesignerHost

The designer host to use when creating components.

defaultValues
IDictionary

A dictionary of property name/value pairs of default values with which to initialize the component.

Returns

An array of created IComponent objects.

Examples

The following code example demonstrates the use of the CreateComponentsCore method in a class derived from ToolboxItem for a custom toolbox item implementation. This code example is part of a larger example provided for the ToolboxItem class.

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

Remarks

If host is not null, the CreateComponentsCore method adds the new components to the designer.

Applies to