add custom .NET control by program
am 08.10.2007 19:26:44 von noemailHi,
I wrote a little app which should add on Toolbox palette my custom controls.
however, it does not work.
it creates well my TAB with my custom name, but it does not add my
custom control.
where is the problem ?
here is the code :
// Create a EnvDTE object.
System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0");
// visual studio 2005
object obj = System.Activator.CreateInstance(t, true);
EnvDTE.DTE env = (EnvDTE.DTE)obj;
// Find the ToolBox Window and ToolBox Tabs collection
Window win = env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
ToolBox tb = (ToolBox)win.Object;
ToolBoxTabs tbts = tb.ToolBoxTabs;
// check if the tabs we will create, already exist
int i = 1;
bool bFound = false;
while ( (i < tbts.Count) && !bFound)
{
if (tbts.Item(i).Name == "RogTech")
{
// the tab already exists, so we will update it with new control version
bFound = true;
}
i++;
}
if (!bFound)
{
// the tab does not exist, so we will create it.
// Insert a new Tab in the tab collection.
ToolBoxTab tbt = tbts.Add("RogTech");
tbt.Activate();
// Insert the new Component.
EnvDTE.ToolBoxItem tbi = tbt.ToolBoxItems.Add("XGrid",
@"XTGrid.dll",
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
// release environment
env.Solution.Close(false);
Marshal.ReleaseComObject(env);
}
thanks a lot,
RAF