How to: Create a Toolbox Control That Uses Windows Forms
The Windows Forms Toolbox Control template that is included in the Visual Studio 2010 SDK lets you create Windows Forms controls that are automatically added to the Toolbox when the extension is installed. This topic shows how to use the template to create a Toolbox control that you can distribute to other users. For a full implementation of a Toolbox control, see Walkthrough: Creating a Windows Forms Toolbox Control.
For more information about the Visual Studio SDK, see Extending Visual Studio Overview. To find out how to download the Visual Studio SDK, see Visual Studio Extensibility Developer Center on the MSDN Web site.
Creating a Toolbox Control
Use the Windows Forms Toolbox Control template to create the project, and then build a user interface (UI) in the designer.
To create a Windows Forms Toolbox Control project
On the File menu, click New, and then click Project.
In the New Project dialog box, under Installed Templates, click the node for your preferred programming language and then click Extensibility. In the list of project types, select Windows Forms Toolbox Control.
In the Name box, type the name you want to use for the project. Click OK.
Visual Studio creates a solution that contains a user control, an attribute to put the control in the Toolbox, and a VSIX manifest for deployment.
To build the control UI
In Solution Explorer, double-click ToolboxControl.cs to open it in the designer.
From the Toolbox, drag any controls you want to the design surface, and arrange them according to your design.
In the Properties window, set public properties on the user control and on the child controls.
Coding the Control
By default, your control will appear in the Toolbox as ToolboxControl1 in a Toolbox item group that has the same name as your solution. You can change these names in the ToolboxControl.cs file.
To code the control
In Solution Explorer, right-click ToolboxControl.cs and then click View Code to open the file in code view.
At the definition of the partial class that implements the control, right-click the class name, click Refactor, and then click Rename. Change the name of the class to the name that you want to be displayed in the Toolbox when the control is installed.
Immediately above the class definition, in the ProvideToolboxControl attribute declaration, change the value of the first parameter to the name of the item group that will host the control in the Toolbox.
The following example shows the ProvideToolboxControl attribute and the adjusted class definition for a control named Counter in the General item group.
[ProvideToolboxControl("General", false)] public partial class Counter : UserControl
Implement the properties, methods, and events for the control.
Building, Testing, and Deployment
Pressing F5 builds the project, which includes a .vsix deployment file, and opens a second instance of Visual Studio that has the control installed in the Toolbox.
To build and test the control
In the new instance of Visual Studio, create a Windows Forms Application project.
Find your control in the Toolbox and drag it to the design surface.
In the Properties window, verify that your properties appear as expected.
Add any code or additional controls that are required to test your methods and events.
Press F5 to open the Windows Forms application.
Verify that the properties, methods, and events of your control behave as expected.
To deploy the control
After you build the tested project, open the \bin\debug\ folder of the project in File Explorer and locate the .vsix file.
Upload the .vsix file to a network or to a Web site.
If you upload the file to the Visual Studio Gallery Web site, other users can use Extension Manager in Visual Studio to find the control and install it.