ToolboxItem.ToolboxItem(Type) Constructor

Initializes a new instance of the ToolboxItem class that creates the specified type of component.

Namespace: System.Drawing.Design
Assembly: System.Drawing (in system.drawing.dll)

public ToolboxItem (
	Type toolType
public ToolboxItem (
	Type toolType
public function ToolboxItem (
	toolType : Type
Not applicable.



The type of IComponent that the toolbox item creates.

Exception typeCondition


The ToolboxItem was locked.

The following code example demonstrates the use of the ToolboxItem constructor 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.

// Toolbox items must be serializable.
class MyToolboxItem : ToolboxItem
    // The add components dialog in Visual Studio looks for a public
    // constructor that takes a type.
    public MyToolboxItem(Type toolType)
        : base(toolType)

    // And you must provide this special constructor for serialization.
    // If you add additional data to MyToolboxItem that you
    // want to serialize, you may override Deserialize and
    // Serialize methods to add that data.  
    MyToolboxItem(SerializationInfo info, StreamingContext context)
        Deserialize(info, context);

    // Let's override the creation code and pop up a dialog.
    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;
                return null;

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0