Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:00:40+00:00 2026-06-12T15:00:40+00:00

I have created a new Visual Studio Addin for create and add my custom

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:00:42+00:00Added an answer on June 12, 2026 at 3:00 pm

    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:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    using EnvDTE;
    using EnvDTE80;
    using System.IO;
    
    namespace InstallToolboxControls
    {
        // Definition of the IMessageFilter interface which we need to implement and 
        // register with the CoRegisterMessageFilter API.
        [ComImport(), Guid("00000016-0000-0000-C000-000000000046"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
        interface IOleMessageFilter // Renamed to avoid confusion w/ System.Windows.Forms.IMessageFilter
        {
            [PreserveSig]
            int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo);
    
            [PreserveSig]
            int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType);
    
            [PreserveSig]
            int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
        }
    
        class Program : IOleMessageFilter
        {
            [DllImport("ole32.dll")]
            private static extern int CoRegisterMessageFilter(IOleMessageFilter newFilter, out IOleMessageFilter oldFilter);
            static string ctrlPath = "WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc";//@"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\WindowsFormsControlLibrary2\v4.0_1.0.0.0__197889249da45bfc\WindowsFormsControlLibrary2.dll";//@"E:\Rostami\Saino\Program\Tests\WindowsFormsControlLibrary2\WindowsFormsControlLibrary2\bin\Debug\WindowsFormsControlLibrary2.dll";
    
            [STAThread]
            public static void Toolbox(string arg)
            {
                Program program = new Program();
                program.Register();
                if (arg.Equals("Install", StringComparison.CurrentCultureIgnoreCase))
                {
                    program.InstallControl();
                }
                else if (arg.Equals("UnInstall", StringComparison.CurrentCultureIgnoreCase))
                {
                    program.UninstallControl();
                }
                program.Revoke();
    
                // to ensure the dte object is actually released, and the devenv.exe process terminates.
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
    
            void InstallControl()
            {
                // Create an instance of the VS IDE,
                Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
                DTE dte = (DTE)System.Activator.CreateInstance(type, true);
    
                // create a temporary winform project;
                string tmpFile = Path.GetFileNameWithoutExtension(Path.GetTempFileName());
                string tmpDir = string.Format("{0}{1}", Path.GetTempPath(), tmpFile);
                Solution2 solution = dte.Solution as Solution2;
                string templatePath = solution.GetProjectTemplate("WindowsApplication.zip", "CSharp");
                Project proj = solution.AddFromTemplate(templatePath, tmpDir, "dummyproj", false);
    
                // add the control to the toolbox.
                EnvDTE.Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
                EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object;
                EnvDTE.ToolBoxTab myTab = toolbox.ToolBoxTabs.Add("Saino");
                myTab.Activate();
                myTab.ToolBoxItems.Add("MyUserControl", ctrlPath, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
                dte.Solution.Close(false);
                Marshal.ReleaseComObject(dte);
                //Console.WriteLine("Control Installed!!!");
            }
    
            void UninstallControl()
            {
                Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
                DTE dte = (DTE)System.Activator.CreateInstance(type, true);
                EnvDTE.Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
                EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)window.Object;
                EnvDTE.ToolBoxTab myTab = toolbox.ToolBoxTabs.Item("Saino");
                myTab.Activate();
                myTab.Delete();
                Marshal.ReleaseComObject(dte);
                //Console.WriteLine("Control Uninstalled!!!");
            }
    
            void Register()
            {
                IOleMessageFilter oldFilter;
                CoRegisterMessageFilter(this, out oldFilter);
            }
    
            void Revoke()
            {
                IOleMessageFilter oldFilter;
                CoRegisterMessageFilter(null, out oldFilter);
            }
    
            #region IOleMessageFilter Members
            public int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo)
            {
                return 0; //SERVERCALL_ISHANDLED
            }
    
            public int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType)
            {
                if (dwRejectType == 2) // SERVERCALL_RETRYLATER
                {
                    return 200; // wait 2 seconds and try again
                }
                return -1; // cancel call
            }
    
            public int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType)
            {
                return 2; //PENDINGMSG_WAITDEFPROCESS
            }
            #endregion
        }
    }
    

    And my codes are as following for Form1.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using InstallToolboxControls;
    
    namespace WindowsFormsApplication12
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                InstallToolboxControls.Program prg = new InstallToolboxControls.Program();
                InstallToolboxControls.Program.Toolbox("Install");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a new silverlight business application in visual studio. It auto generates
I have Qt SDK and Visual Studio Qt Add-In working in VS2008. I created
I have a custom list definition created via visual studio 2010. I would like
I have just created a new project in VS2010 using the Visual c# >
For a new project I have created a local folder tree with empty Visual
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I am new to using Microsoft development tools but have been using Visual Studio
I am experiencing some annoying behavior with Visual Studio .NET 2008. We have created
I want to create logical folders in visual studio which could have different structures
I have created my first dll using c# and visual studio 2010. I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.