Adding a Menu to the Visual Studio Menu Bar within an Add-In

血红的双手。 提交于 2019-12-02 01:04:27
    public static CommandBarControl GetCustomMenu(DTE2 applicationObject)
    {
        //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items
        CommandBar menuBarCommandBar = ((CommandBars)applicationObject.CommandBars)["MenuBar"];

        //Find the Tools command bar on the MenuBar command bar as we want to add it before it
        CommandBarControl toolsControl = menuBarCommandBar.Controls["Tools"];

        CommandBarControl myMenu;

        try
        {
            // Get the menu bar if it already exists
            myMenu = menuBarCommandBar.Controls["My Menu"];
        }
        catch (Exception)
        {
            // Doesnt exist so crate a new one.
            myMenu = menuBarCommandBar.Controls.Add(Type: MsoControlType.msoControlPopup, Id: 1234567890, Before: toolsControl.Index - 1);
            myMenu.Caption = "My Menu"];;
        }
        return myMenu;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!