none
关于自定义控件安装创建工具栏选项卡的问题 RRS feed

  • 常规讨论

  • 我自定义了自定义控件。想提供一个安装包,然后把控件安装到VS里,并在工具栏中创建一个选项卡,把我的控件全放在下面。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration.Install;
    using EnvDTE;
    using System.Windows.Forms;
    namespace SetupLibrary
    {
        [RunInstaller(true)]
        public partial class RegControls : Installer
        {
            private const string TabName = "金智WEB控件";
            public RegControls()
            {
                InitializeComponent();
                this.AfterInstall+=new InstallEventHandler(Installer_AfterInstall);
            }
            public void Installer_AfterInstall(object sender, InstallEventArgs e)
            {
                //string   progpath=Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                string progpath = this.Context.Parameters["targetdir"];
                
                try
                {
                    Type latestDTE = Type.GetTypeFromProgID("VisualStudio.DTE");
                    EnvDTE.DTE dte = Activator.CreateInstance(latestDTE) as EnvDTE.DTE;
                    if (dte != null)
                    {
                        Window win = dte.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
                        ToolBox tb = (ToolBox)win.Object;
                        //选项卡集合
                        ToolBoxTabs tbts = tb.ToolBoxTabs;
                        ToolBoxTab tbt = null;
                        ToolBoxTab mytab = null;
    
                        foreach (ToolBoxTab t in tbts)
                        {
                            if (t.Name == TabName)
                                mytab = t;
                        }
                        if (mytab != null)
                        {
                            foreach (ToolBoxItem ti in mytab.ToolBoxItems)
                            {
                                if (ti.Name == "GoldWisdom")
                                    ti.Delete();
                            }
                            tbt.Activate();
                            dte.ExecuteCommand("View.PropertiesWindow", String.Empty);
                            tbt.ToolBoxItems.Add("GoldWisdom", progpath + "GoldWisdom.dll", vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
                            
                        }
                        else
                        {
                            mytab = tbts.Add(TabName);
                            [color=#FF0000]System.Windows.Forms.MessageBox.Show("ADD tab success");[/color]
                            foreach (ToolBoxItem ti in mytab.ToolBoxItems)
                            {
                                if (ti.Name == "GoldWisdom")
                                    ti.Delete();
                            }
                        }
                        mytab.Activate();
                        dte.ExecuteCommand("View.PropertiesWindow", String.Empty);
                        mytab.ToolBoxItems.Add("GoldWisdoms", progpath + "GoldWisdom.dll", vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
                       [color=#FF0000] System.Windows.Forms.MessageBox.Show("ADD dll success");[/color]
                    }
                    else
                        System.Windows.Forms.MessageBox.Show("未能将GWEdit控件加入Visual   Studio的工具箱中,您需要在安装结束后手动加入!");
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("未能将GWEdit控件加入Visual   Studio的工具箱中,您需要在安装结束后手动加入!" + Environment.NewLine + ex.Message);
                }
            }
        }
    }
    2009年10月14日 5:40

全部回复