Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 23rd, 2007, 07:27 AM
Registered User
Join Date: Apr 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# adding custom controls in vs toolbox


I have developed some custom controls and now im doing the setup. I need to insert them into vs toolbar at the setup. For this i created a console application which is launched before setup is done.

I used DTE and some Reflection.

The main ideea is that i look if vs is opened then i get the toolbar object create a tab and add the controls from the assembly. If the vs is not opened or is opend but is running and you dont have acces to the toolbox object (for exemple is running the some code for debug) i create a new instance of vs and add the tab and the controls.

Well my problem is when i create a new instance. I get the toolbox object i add the tab but the controls r not added in the tab. I cant find the problem.

Heres the part of interest for this job.

1. Getting the vs instance :::

public static DTE GetDesignTimeEnvironment(DTEVersion dteVersion, ref bool alreadyCreated)
            alreadyCreated = false;
            string progID = GetEnumDescription(dteVersion);

            DTE result;
                //Determine if there is an open VS.Net
                result = (DTE) Marshal.GetActiveObject(progID);

                //Try to show properties window, if it fails VS.Net is in run-time
                //you have to open a new VS.Net
                    result.ExecuteCommand("View.PropertiesWindow", "");
                    alreadyCreated = true;
                catch //You have to open a new VS.Net
                    result = null;
            catch //There is no open VS.Net
                result = null;

            if(result == null)
                //Open a new VS.Net
                Type type = Type.GetTypeFromProgID(progID);
                if(type != null)
                    result = (DTE)Activator.CreateInstance(type);

            return result;

2. Try to insert them :::

internal static bool RegisterControls(DTE dte, bool alreadyCreatedDTE, VSControl[] controls)
            Window toolbox = dte.Windows.Item(EnvDTE.Constants.vsWindowKindTool box);
            ToolBoxTabs tabs = ((ToolBox) toolbox.Object).ToolBoxTabs;
            dte.ExecuteCommand("View.PropertiesWindow", "");

            foreach(VSControl control in controls)
                ToolBoxTab tab;
                    if(GetToolBoxTab(tabs, control.TabName) == null)
                        tab = tabs.Add(control.TabName);
                    tab = GetToolBoxTab(tabs, control.TabName);
                    if(tab != null && !control.IsToolBoxTab)
                        tab.ToolBoxItems.Add("MyControls", control.AssemblyPath, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETCompo nent);


            return true;

private static ToolBoxTab GetToolBoxTab(ToolBoxTabs tabs, string tabName)
            foreach(ToolBoxTab tab in tabs)
                if (smenglish.CompareInfo.Compare(tab.Name, tabName, CompareOptions.IgnoreCase) == 0)
                    return tab;

            return null;

It seems that in the GetToolBoxTab(..) when vs is not opend and i create an instance each tab.Name trows execptions. I guess the toolbox object is not avaible. What can i do ?

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Controls kcis8rm ASP.NET 2.0 Basics 2 July 2nd, 2007 04:07 PM
how to add controls to the visual studio toolbox luisjeronimo BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 June 28th, 2007 04:44 PM
Adding Custom Controls to the Studio's toolbar devdev Visual Studio 2005 0 May 21st, 2006 04:17 PM
Custom Controls apry BOOK: Beginning ASP.NET 1.0 2 May 23rd, 2004 11:04 PM
Adding controls to Toolbox results in two entries DolphinBay VS.NET 2002/2003 4 April 2nd, 2004 07:56 PM

All times are GMT -4. The time now is 10:11 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.