Adding Controls to Toolbox With Add-In

P

Pham Nguyen

I'm having problems creating an add-in to install a library of custom
controls I have in the toolbox. I've created a Visual Studio .NET
Add-in project and implemented this code in the OnConnection() method:

public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{

DTE env = (DTE)application;
// env.ExecuteCommand("View.PropertiesWindow", String.Empty);

Window win =
env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
ToolBox tb = (ToolBox)win.Object;
ToolBoxTabs tbts = tb.ToolBoxTabs;
ToolBoxTab tbt = tbts.Add("My Tab");
tbt.Activate();
tbt.ToolBoxItems.Add("", @"D:\Controls\MyControls.dll",
vsToolBoxItemFormat.vsToolBoxItemFormatText);
tbt.ToolBoxItems.Add("My Text Item", "My Text...",
vsToolBoxItemFormat.vsToolBoxItemFormatText);
}

The text item gets added just fine, but none of the controls get
loaded (if I put in a bogus path for the controls DLL, though, I do
get an error). I read about a possible bug in VS.NET where controls
will not get added if the Properties window isn't open, but when I
uncomment the line in the code above that does that, I get a "Not
enough storage is available to complete the operation" error. Is there
something off about the code above?
 
P

Pham Nguyen

Sorry, there was a typo in the code. The line that is supposed to add
the controls is:

tbt.ToolBoxItems.Add("", @"D:\Controls\MyControls.dll",
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,829
Messages
2,569,737
Members
45,525
Latest member
RosalindSa

Latest Threads

Top