Exemple #1
0
        /// <summary>
        /// This method adds a Toolbox item by DTE automation model
        /// </summary>
        private void AddItemByDTE()
        {
            // Get tabs from automation model
            ToolBoxTabs tabs = _applicationObject.ToolWindows.ToolBox.ToolBoxTabs;
            IEnumerator e = tabs.GetEnumerator();

            ToolBoxTab tab = null;
            while (e.MoveNext())
            {
                ToolBoxTab ct = e.Current as ToolBoxTab;
                if (ct.Name == "CustomTab")
                {
                    tab = ct;
                    break;
                }
            }

            // If there is no CustomTab, add one
            if (tab == null)
                tab = tabs.Add("CustomTab");

            // Add Toolbox Item, but we can't customize other information for 
            // Toolbox item like icon and transparency.
            tab.ToolBoxItems.Add(
                "DTE Added HTML Content", 
                "<input id=\"Button1\" type=\"button\" value=\"button\" />", 
                vsToolBoxItemFormat.vsToolBoxItemFormatHTML);
        }
        private void InstallTab(EnvDTE80.DTE2 dteObject)
        {
            ToolBox     tlBox   = null;
            ToolBoxTabs tbxTabs = null;
            ToolBoxTab2 tbxTab  = null;

            try {
                // Create an object reference to the IDE's ToolBox object and
                // its tabs.
                tlBox   = (ToolBox)(dteObject.Windows.Item(Constants.vsWindowKindToolbox).Object);
                tbxTabs = tlBox.ToolBoxTabs;

                bool tabExists = false;

                tlbTab = null;
                if (!tabExists)
                {
                    try {
                        // Add a new tab to the Toolbox and select it.
                        tbxTab = (ToolBoxTab2)tbxTabs.Add(txtTabName.Text);
                        tbxTab.Activate();
                    }
                    catch {
                        MessageBox.Show("An error occured during toolbox tab installation: Tab not created.", "Add Tab", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        btnAdd.Text = "&Finish";
                        return;
                    }


                    bool success = true;
                    assemblyName = Path.Combine(InstallPath, "Comzept.NetRix.Professional.UI.dll");
                    string error = "";
                    if (File.Exists(assemblyName))
                    {
                        tbxTabs.Item(txtTabName.Text).Activate();


                        tbxTabs.Item(txtTabName.Text).ToolBoxItems.Add(txtTabName.Text, assemblyName, vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
                    }
                    else
                    {
                        success = false;
                        error  += "\nError description:\nPath (1) not found: " + assemblyName;
                    }

                    if (success)
                    {
                        MessageBox.Show(txtTabName.Text + " and selected controls successfully added to ToolBox.", "Add/Remove", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        btnAdd.Text = "&Next >";
                    }
                    else
                    {
                        MessageBox.Show("An error occured during installation: " + error, "Add/Remove", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        btnAdd.Text = "&Finish";
                    }
                    Close();
                }
            } catch (System.Exception ex) {
                MessageBox.Show("An unexpected error occurred during installation:\n\n" + ex.Message, "Add/Remove", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }