|
Re: Adding controls to toolbox at install time: msg#00019org.user-groups.dotnet.padnug
OK guys, here's the code for this. Don't say I never gave you nothin ;) It's from a console app. This code adds a toolbar called "MyNew" and some controls that are located in a passed in dllPath. Visual Studio really should be closed while you do this. There is some strangeness here; the EnvDTE namespace isn't as polished as it should be. ---------------------- public static string AddMyNewToolbar(string dllPath) { // reference: http://weblogs.asp.net/savanness/archive/2003/04/10/5352.aspx string result = ""; Type latestDTE = Type.GetTypeFromProgID("VisualStudio.DTE.7.1"); EnvDTE.DTE env = Activator.CreateInstance(latestDTE) as EnvDTE.DTE; try { //string dllPath = RuntimeEnvironment.GetRuntimeDirectory() + "bin\\MyControls.dll"; #if DEBUG Console.WriteLine("DLL Path is: " + dllPath); #endif // Prepare to munge the toolbox -- get toolbox window, object, and tabs collection EnvDTE.Window toolboxWindow = env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox); EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)toolboxWindow.Object; EnvDTE.ToolBoxTabs toolboxTabs = toolbox.ToolBoxTabs; // Careful to check if our tab already exists foreach (EnvDTE.ToolBoxTab tab in toolboxTabs) { if (tab.Name == "MyNew") { Console.WriteLine("Toolbar exists!"); return result; } } // No, so add it EnvDTE.ToolBoxTab newtab = toolboxTabs.Add("MyNew"); // WinBug: gotta show the Properties window, first env.ExecuteCommand("View.PropertiesWindow", ""); // WinBug2: gotta activate the tab and select the first item newtab.Activate(); newtab.ToolBoxItems.Item(1).Select(); // Finally: add the controls newtab.ToolBoxItems.Add( @"Button", dllPath, EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent ); Console.WriteLine("Toolbar added successfully."); // not sure if this line works, caveat emptor env.Application.MainWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); } catch(Exception exc) { Console.WriteLine("Add toolbar failed.\r\n\r\n" + exc.Message); return "Exception: " + exc.Message; } return result; } Justin Collum wrote: >Does anyone out there have any experience (read: working code) that adds a >tab to the IDE toolbox during an app's install? I've found a few samples out >there but they don't necessarily work. My best effort met with the dreaded >"Unspecified error." > >-- Justin > > >[Non-text portions of this message have been removed] > > > > > >Yahoo! Groups Links > > > > > > > > > > > |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Two .Net job openings: 00019, Liz Gee |
|---|---|
| Next by Date: | Philosophical take on how to fetch a data structure from SQL Server 2000: 00019, Liz Gee |
| Previous by Thread: | Two .Net job openingsi: 00019, Liz Gee |
| Next by Thread: | Philosophical take on how to fetch a data structure from SQL Server 2000: 00019, Liz Gee |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |