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)

Source:
ToolboxItem.cs
Source:
ToolboxItem.cs
Source:
ToolboxItem.cs

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

C#
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host);
C#
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host);

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

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

CreateComponentsCore(IDesignerHost, IDictionary)

Source:
ToolboxItem.cs
Source:
ToolboxItem.cs
Source:
ToolboxItem.cs

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

C#
protected virtual System.ComponentModel.IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host, System.Collections.IDictionary defaultValues);
C#
protected virtual System.ComponentModel.IComponent[]? CreateComponentsCore(System.ComponentModel.Design.IDesignerHost? host, System.Collections.IDictionary? defaultValues);

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.

C#
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;
        }
    }
}

Remarks

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

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10