all groups > visual studio .net ide > february 2004 >
You're in the

visual studio .net ide

group:

Adding a single ToolBoxItem to a ToolBoxTab


Adding a single ToolBoxItem to a ToolBoxTab muspam2004 NO[at]SPAM yahoo.com
2/26/2004 7:18:04 AM
visual studio .net ide:
Hi,
I need to add a new ToolBox Tab called "MyTab" to the toolBox which i
am able to do sucessfully using an AddIn.
But my problem is i have an Assembly called "MyAssembly.dll" which
contains 5 of my controls.
But i need to add only 1 or 2 control from that assembly as
toolboxitem inside my tab.
My code to add the toolboxitem is:
System.Reflection.Assembly asm;
asm=Assembly.Load("MyAssembly,Version=1.2.0.0,Culture=neutral,PublicKeyToken=43c1947e29e3e2ed");
ToolBoxItem item = mckProcessItemtab.ToolBoxItems.Add
("MyControl1",asm.CodeBase,vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
But what this does is it adds all the controls that are present in the
assembly to the ToolBoxtab(MyTab).
Is there any way that i can specify for only some controls to be added
to the tab.
And i cannot use the ToolBoxItem(false) because i need to add all the
controls in the assembly but in differnet tabs.
Thanks in advance,

Regards,
Re: Adding a single ToolBoxItem to a ToolBoxTab muspam2004 NO[at]SPAM yahoo.com
3/1/2004 7:33:43 AM
Hi,
I figured out it myself.
There are 2 method signatures for the ToolBoxITems Add method.
<AssemblyNameInTheGAC> — This is a single class listed as an
assembly-qualified reference. Single classes can be added as controls
provided they are references to an assembly that is in the GAC, such
as: WindowControlLibrary1.UserControl1, WindowControlLibrary,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=<Your Token>." (You
would replace <Your Token> with your public key token, which is
required to add your assembly to the GAC
The mistake that i was making was not specifying the fullname of the
assembly without which it does not load the assembly nor does it give
an exception..
The code for adding a single toolboxitem is as follows:

public void AddTab()
{
try
{
string TabName="MyTab";
//Get toolbox window, object, and tabs collection
Window toolboxWindow =
applicationObject.Windows.Item(Constants.vsWindowKindToolbox);
ToolBox toolbox = (ToolBox) toolboxWindow.Object;

ToolBoxTabs tabs = toolbox.ToolBoxTabs;

ToolBoxTab itemTab;

//Check to see if the Tab already exists..
foreach (EnvDTE.ToolBoxTab tab in tabs)
{

if (tab.Name == TabName)
return;
}

//If not then add the Tab to the TabCollection.
itemTab = tabs.Add(TabName);

//Gotta show the Properties Window and activate the tab and select
the First Item...
itemTab.Activate();
applicationObject.ExecuteCommand("View.PropertiesWindow", "");

itemTab.ToolBoxItems.Item(1).Select();
//MyAssembly must be installed in the GAC and to install it
in GAC it must be strongly named.
ToolBoxItem item = itemTab.ToolBoxItems.Add
("Control1","MyAssembly.Control1,MyAssembly, Version 1.1.0.0,
Culture=neutral,PublicKeyToken=34c2047e56e3e8de",vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);

}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}

}

Call it on the OnStartupComplete to add the ToolBoxItem tab when the
VS.NET IDE is loaded.
public void OnStartupComplete(ref System.Array custom)
{
if(this.addInInstance != null && this.addInInstance.Connected)
{

AddTab();

}
}
Hope this will be helpfull to someone in the future.

Regards,
Konar...

[quoted text, click to view]
AddThis Social Bookmark Button