I have created a new Visual Studio Addin for create and add my custom tab in the Visual Studio toolbox and add new items (controls) to my custom tab. Codes work for add new tab to the Visual Studio toolbox, but not work for add new items (controls) to my tab.
My Visual Studio Addin code is:
using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using EnvDTE100;
using System.Windows.Forms;
namespace MyAddin1
{
/// <summary>The object for implementing an Add-in.</summary>
/// <seealso class='IDTExtensibility2' />
public class Connect : IDTExtensibility2
{
/// <summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
public Connect()
{
}
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
/// <param term='application'>Root object of the host application.</param>
/// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
/// <param term='addInInst'>Object representing this Add-in.</param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
ToolboxExample(_applicationObject);
}
public void ToolboxExample(DTE2 dte)
{
ToolBox tlBox = null;
ToolBoxTabs tbxTabs = null;
ToolBoxTab3 tbxTab = null;
try
{
tlBox = (ToolBox)(dte.Windows.Item(Constants.vsWindowKindToolbox).Object);
tbxTabs = tlBox.ToolBoxTabs;
tbxTab = (ToolBoxTab3)tbxTabs.Add("MRS");
tbxTab.Activate();
tbxTab.ToolBoxItems.Add("FloorsGrouping", @"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsFormsControlLibrary2\v4.0_1.0.0.0__197889249da45bfc\WindowsFormsControlLibrary2.dll", vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
}
catch (System.Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
}
private DTE2 _applicationObject;
private AddIn _addInInstance;
}
}
Following line of code not works:
tbxTab.ToolBoxItems.Add("FloorsGrouping", @"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsFormsControlLibrary2\v4.0_1.0.0.0__197889249da45bfc\WindowsFormsControlLibrary2.dll", vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
I change
tbxTab.ToolBoxItems.Add
with:
tbxTabs.Item("MRS").ToolBoxItems.Add
However, it didn’t work for me. Even I change
@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsFormsControlLibrary2\v4.0_1.0.0.0__197889249da45bfc\WindowsFormsControlLibrary2.dll"
with following code lines and test them one by one:
@"E:\Rostami\Saino\WindowsFormsControlLibrary2.dll"
and
"WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc"
However, it didn’t work for me again.
My custom control main class name is FloorsGrouping, and its display name is:
[DisplayName("Floors Group")]
And its assembly name in the GAC is:
[Editor("WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc", typeof(UITypeEditor))]
I searched the internet for any solutions, and I only find several solutions that describe adding new tab to the Visual Studio toolbox and adding controls to tab just possible from Visual Studio Addin.
I found the solution and could add my custom tab to the Visual Studio toolbox and add my custom controls to my custom tab with Windows Forms Application project and not from Visual Studio Add-in project. I describe it as follows:
In Windows Forms Application project, first, we must create an instance of Visual Studio IDE. Then, must create a temporary Windows Forms Application project and next, must add our custom tab to the Visual Studio toolbox and add our custom controls to our custom tab.
My codes are as following for Class1.cs:
And my codes are as following for Form1.cs: