private void RemoveToolBoxItem(EnvDTE.DTE env) { EnvDTE.Window toolboxWindow = env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox); EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)toolboxWindow.Object; EnvDTE.ToolBoxTabs toolboxTabs = toolbox.ToolBoxTabs; foreach (EnvDTE.ToolBoxTab tab in toolboxTabs) { if (tab.Name == this.TabName) { foreach (EnvDTE.ToolBoxItem item in tab.ToolBoxItems) { try { item.Delete(); } catch (Exception) {} } try { tab.Delete(); } catch (Exception) {} } } env.Quit(); }
private void AddToolBoxItem(EnvDTE.DTE env) { EnvDTE.Window toolboxWindow = env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox); EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)toolboxWindow.Object; EnvDTE.ToolBoxTabs toolboxTabs = toolbox.ToolBoxTabs; EnvDTE.ToolBoxTab newTab = null; bool tabExists = false; foreach (EnvDTE.ToolBoxTab tab in toolboxTabs) { if (tab.Name == this.TabName) { newTab = tab; tabExists = true; break; } } if (!tabExists) { newTab = toolboxTabs.Add(this.TabName); } newTab.Activate(); env.ExecuteCommand("View.PropertiesWindow", ""); newTab.ToolBoxItems.Item(1).Select(); newTab.ToolBoxItems.Add(this.ComponentName, this.ComponentPath, EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent); env.Quit(); }