Windows Forms Programming 
Walkthrough: Automatically Populating the Toolbox with Custom Components 

If your components are defined by a project in the currently open solution, they will automatically appear in the Toolbox, with no action required by you. You can also manually populate the Toolbox with your custom components by using the Choose Toolbox Items Dialog Box (Visual Studio), but the Toolbox takes account of items in your solution's build outputs with all the following characteristics:

NoteNote

The Toolbox does not follow reference chains, so it will not display items that are not built by a project in your solution.

This walkthrough demonstrates how a custom component automatically appears in the Toolbox once the component is built. Tasks illustrated in this walkthrough include:

  • Creating a Windows Forms project.

  • Creating a custom component.

  • Creating an instance of a custom component.

  • Unloading and reloading a custom component.

When you are finished, you will see that the Toolbox is populated with a component that you have created.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Creating the Project

The first step is to create the project and to set up the form.

To create the project

  1. Create a Windows-based application project called ToolboxExample.

    For more information, see How to: Create a Windows Application Project.

  2. Add a new component to the project. Call it DemoComponent.

    For more information, see How to: Add Existing Items to a Project.

  3. Build the project.

Creating an Instance of a Custom Component

The next step is to create an instance of the custom component on the form. Because the Toolbox automatically accounts for the new component, this is as easy as creating any other component or control.

To create an instance of a custom component

  1. Open the project's form in the Forms Designer.

  2. In the Toolbox, click the new tab called ToolboxExample Components tab.

    Once you click the tab, you will see DemoComponent.

    NoteNote

    For performance reasons, components in the auto-populated area of the Toolbox do not display custom bitmaps, and the ToolboxBitmapAttribute is not supported.

  3. Drag your component onto your form.

    An instance of the component is created and added to the Component Tray.

Unloading and Reloading a Custom Component

The Toolbox takes account of the components in each loaded project, and when a project is unloaded, it removes references to the project's components.

To experiment with the effect on the Toolbox of unloading and reloading components

  1. Unload the project from the solution.

    For more information about unloading projects, see How to: Unload and Reload Projects. If you are prompted to save, choose Yes.

  2. Add a new Windows Application project to the solution. Open the form in the Designer.

    The ToolboxExample Components tab from the previous project is now gone.

  3. Reload the ToolboxExample project.

    The ToolboxExample Components tab now reappears.

Next Steps

This walkthrough demonstrates that the Toolbox takes account of a project's components, but the Toolbox is also takes account of controls. Experiment with your own custom controls by adding and removing control projects from your solution.

See Also

Tasks

How to: Manipulate Toolbox Tabs

Reference

Choose Toolbox Items Dialog Box (Visual Studio)

Other Resources

Putting Controls on Windows Forms

Tags :


Community Content

MollyBos - MSFT
AutoToolboxPopulate option

This automatic adding of components in a project to the toolbox is controlled by an option named "AutoToolboxPopulate," which can be found under Tools->Options, then Windows Forms Designer->General->Toolbox. This frustrated me for half a day as to why it didn't work.

At the very least this article absolutely needs to contain a link to documentation on that option.

This blog post provides some useful info about AutoPopulateToolbox: http://blog.jeffhandley.com/index.php/2006/08/17/vs-2005-difficulties-and-workarounds/. Also, see this Connect bug which provides additional workaround for getting a user control to show up in the toolbox: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=144156.


Page view tracker