Click here to Skip to main content
11,920,772 members (56,023 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked

Deploying Controls to VS.NET ToolBox Programatically

, 1 Oct 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
This article explains on how to deploy custom controls and components to a particular tab in Visual Studio Toolbox programatically. This can be used with installer programs for automatic deployment.

Sample Image - AddItemToToolBar.jpg


In this article, we will walk through the process of adding custom web/Windows controls and components to the Visual Studio Toolbox, using code. This article will be helpful for control developers who want to deploy their controls into a single package to clients. The client need not have to do the extra work of referencing the controls from the Visual Studio editor and adding it to the Toolbox. Once this application is run, it automatically adds all the controls to the Toolbox, and the developer can drag and drop the components on to the page and use it.

The executable can be called from an installer program as a custom action also.


This article assumes a basic familiarity with Visual Studio 2003, Windows Forms programming in the .NET Framework using C# or Visual Basic .NET, and some basics into the mechanism of Reflection and DTE concepts.

The Code

This piece of code actually uses Reflection to create an instance of Visual Studio .DTE.7.1. In Visual Studio, the DTE object is the root of the automation model, which other object models often call "Application". "DTE" is an acronym that stands for "Development Tools Environment".

//EnvDTE class cannot be instantiated using the new keyword
//instead use Reflection to get an instance of the DTE Object.
System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.7.1"); 
object obj = System.Activator.CreateInstance(t, true); 
dteObject = (EnvDTE.DTE)obj;

Once an object of DTE is obtained, all methods and properties for the particular type can be accessed, and using these properties and methods, we will be adding the items to the toolbox.

This code block shows us how to get an instance of the window object corresponding to the Visual Studio Toolbox:

//Gets the window Object corrsponding to the visual Studio Toolbox

ToolBoxWnd = dteObject.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
tlbTabs = ((ToolBox)ToolBoxWnd.Object).ToolBoxTabs;

The ToolBoxTabs object provides a set of methods and properties to access the Toolbox and its Items collection. Using the methods, new items can be added or deleted form the collection. The code sample below creates a new tab using the name specified by the user and adds the controls contained inside the DLL file loaded by the user.

tlbTab = tlbTabs.Add("My New Tab");
ToolBoxWnd.Visible = true;
tlbTab.ToolBoxItems.Add("MY New Tab", "C:\\MyControl.dll", 

The toolbox window has to be made visible and the current toolbox tab has to be activated before any controls can be loaded to the tab, else the controls will get added to the default tab.

The add method of the ToolBoxItems takes 3 parameters:

  1. Name of the tab to which the controls are to be added.
  2. Path to the component to be added to the toolbox (DLL file).
  3. The format for the toolbox item, can be a control or a simple text segment.

The demo project includes a UI where the user can choose a DLL file to load and can add or delete items. The project can be modified to strip off all the UI part with just a basic form, and all the code for adding the items can be written in the form_load section.

Create an executable file with this application and the EXE can be used with an installer program that runs this executable which in turn adds all the controls to the toolbox.

Creating a Setup and Deployment Project

Open Visual Studio and select Setup and Deployment Project from the New Project screen, and select Setup Project, provide it with a location, and open the project. Copy all application files and DLLs to the application folder; dependencies are automatically detected and added.

Setup Screen

Click Custom Actions editor from the Solution Explorer window, the left pane will now show four default actions for the installer: Install, Commit, Rollback and Uninstall.

Setup ScreenShot

Right click on Install and select Add Custom Action, this opens up a dialog box to add a custom action file, select the executable file "AddToToolBar.exe" and add the file. After adding the file, set the CustomInstaller property for the added file to "False". This should invoke the EXE file from the installer.

Setup Screenshot

Build the Setup project and the controls package is ready to be deployed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
Kannan has 4+ years of experience in software development, he started his career in VB and asp application development and as new technologies evolved, he felt the need to make use of the advanced functionalities, develop complex applications and take up challenging tasks, it was then when he started falling in love with the DotNet architecture and concepts which really enthralled him do do more projects in dotnet and get to use the full potential of DotNet. He specialises in development of Custom controls and components and tools. He is a Microsoft Certified Applications Developer working with a Fortune 500 Giant in Bangalore, India

Kannan is a fun loving person, likes to wander around in the hills, sometimes he gets glued to the computer doing some serious stuff or trying to get something to work. More information about him is available on his site.

Visit my Blog at

You may also be interested in...

Comments and Discussions

GeneralOnly Tabs get added but not the controls Pin
priya122119-Jan-10 23:40
memberpriya122119-Jan-10 23:40 
QuestionProgrammatically to load wpf custom controls to vs2008 toolbox in windows application Pin
sivat51818-Aug-09 1:23
membersivat51818-Aug-09 1:23 
QuestionHow to Load WPF Custom controls programatically to the toolBox? Pin
BharathGandhi16-Feb-09 18:39
memberBharathGandhi16-Feb-09 18:39 
AnswerRe: How to Load WPF Custom controls programatically to the toolBox? Pin
Kannan.V17-Feb-09 9:39
memberKannan.V17-Feb-09 9:39 
QuestionChange 'Banner Text' of 'Welcome' User Interface Dialog ? Pin
Aniket Salunkhe11-Jan-07 23:35
memberAniket Salunkhe11-Jan-07 23:35 
AnswerRe: Change 'Banner Text' of 'Welcome' User Interface Dialog ? Pin
Kannan.V12-Jan-07 10:03
memberKannan.V12-Jan-07 10:03 
GeneralRe: Change 'Banner Text' of 'Welcome' User Interface Dialog ? Pin
Aniket Salunkhe13-Jan-07 7:27
memberAniket Salunkhe13-Jan-07 7:27 
GeneralIt works in VS 2003 if you do this... Pin
Andrew MacDougall16-Mar-06 13:52
memberAndrew MacDougall16-Mar-06 13:52 
QuestionMultiple Controls in DLL - multiple tabs? Pin
Bryan Cairns9-Jan-06 17:01
memberBryan Cairns9-Jan-06 17:01 
AnswerRe: Multiple Controls in DLL - multiple tabs? Pin
Kannan.V10-Jan-06 11:20
memberKannan.V10-Jan-06 11:20 
AnswerRe: Multiple Controls in DLL - multiple tabs? Pin
Member 237901623-Feb-09 14:38
memberMember 237901623-Feb-09 14:38 
GeneralTab get added to the toolbox but not the controls! Pin
Padmavathy Thiruvenkadam10-Nov-05 1:10
memberPadmavathy Thiruvenkadam10-Nov-05 1:10 
GeneralRe: Tab get added to the toolbox but not the controls! Pin
Kannan.V10-Nov-05 13:52
memberKannan.V10-Nov-05 13:52 
GeneralA little help, please Pin
matheussi5-Sep-05 4:57
membermatheussi5-Sep-05 4:57 
Hello. First, congratulations! The article is great!

Im trying to use your example, but the ide (visual studio .net 2003) send me the exception message: The type or namespace name 'EnvDTE' could not be found (are you missing a using directive or an assembly reference?)

Please, what's wrong?


Denis Matheussi
GeneralRe: A little help, please Pin
Kannan.V5-Sep-05 23:09
memberKannan.V5-Sep-05 23:09 
GeneralRe: A little help, please Pin
matheussi6-Sep-05 3:54
membermatheussi6-Sep-05 3:54 
General[Msg Deleted] Pin
matheussi6-Sep-05 4:02
membermatheussi6-Sep-05 4:02 
GeneralTab not visible for all Projects Pin
rsarun10-May-05 1:19
sussrsarun10-May-05 1:19 
GeneralRe: Tab not visible for all Projects Pin
Kannan.V10-May-05 7:23
memberKannan.V10-May-05 7:23 
GeneralRe: Tab not visible for all Projects Pin
rsarun10-May-05 22:43
sussrsarun10-May-05 22:43 
GeneralRe: Tab not visible for all Projects Pin
rsarun11-May-05 4:14
sussrsarun11-May-05 4:14 
QuestionWhy "View.PropertiesWindow" ? Pin
ajproch13-Apr-05 6:19
memberajproch13-Apr-05 6:19 
AnswerRe: Why "View.PropertiesWindow" ? Pin
Kannan.V13-Apr-05 7:52
memberKannan.V13-Apr-05 7:52 
GeneralRe: Why "View.PropertiesWindow" ? Pin
ajproch13-Apr-05 11:21
memberajproch13-Apr-05 11:21 
Generalthink you have a bug Pin
JCollum29-Dec-04 14:57
memberJCollum29-Dec-04 14:57 
Generalsomebody Pin
punk_ssa21-Dec-04 15:48
memberpunk_ssa21-Dec-04 15:48 
GeneralRe: somebody Pin
Anonymous22-Dec-04 4:21
sussAnonymous22-Dec-04 4:21 
GeneralRe: somebody Pin
punk_ssa22-Dec-04 9:33
memberpunk_ssa22-Dec-04 9:33 
GeneralRe: somebody Pin
Anonymous23-Dec-04 4:04
sussAnonymous23-Dec-04 4:04 
GeneralRe: somebody Pin
punk_ssa23-Dec-04 7:20
memberpunk_ssa23-Dec-04 7:20 
GeneralRe: somebody Pin
punk_ssa23-Dec-04 7:22
memberpunk_ssa23-Dec-04 7:22 
Generals Pin
Anonymous10-Dec-04 19:16
sussAnonymous10-Dec-04 19:16 
GeneralTabs do not show up in IDE Pin
Grant A Frisken8-Dec-04 14:44
memberGrant A Frisken8-Dec-04 14:44 
GeneralRe: Tabs do not show up in IDE Pin
Grant A Frisken8-Dec-04 18:29
memberGrant A Frisken8-Dec-04 18:29 
GeneralRe: Tabs do not show up in IDE Pin
Grant A Frisken8-Dec-04 20:13
memberGrant A Frisken8-Dec-04 20:13 
GeneralRe: Tabs do not show up in IDE Pin
Kannan.V9-Dec-04 3:54
memberKannan.V9-Dec-04 3:54 
GeneralRe: Tabs do not show up in IDE Pin
Grant A Frisken9-Dec-04 11:56
memberGrant A Frisken9-Dec-04 11:56 
GeneralRe: Tabs do not show up in IDE Pin
JCollum29-Dec-04 14:52
memberJCollum29-Dec-04 14:52 
GeneralMissing download Pin
Smitha Vijayan3-Oct-04 21:30
staffSmitha Vijayan3-Oct-04 21:30 
GeneralRe: Missing download Pin
Kannan.V4-Oct-04 7:57
memberKannan.V4-Oct-04 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151120.1 | Last Updated 2 Oct 2004
Article Copyright 2004 by Kannan.V
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid