添加菜单到Visual Studio菜单栏内的加载项 [英] Adding a Menu to the Visual Studio Menu Bar within an Add-In

查看:308
本文介绍了添加菜单到Visual Studio菜单栏内的加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能创建一个内加载项添加自定义菜单在Visual Studio中的主菜单栏?

我要外接创建一个公司具体的菜单,如果它不存在,然后添加自己的特定命令的菜单。这样,如果提供多个​​加载项,然后它们都可以添加的命令相同的菜单。

我在创造一个发现了一个 MSDN链接了演练其中VSPackage的做到这一点,但没有从内部的加载项,它需要有自己的特定的安装/注册。

解决方案

 公共静态的CommandBarControl GetCustomMenu(DTE2的applicationObject)
    {
        //找到的MenuBar命令栏,这是顶级命令栏保持所有主菜单项
        命令栏menuBarCommandBar =((命令栏)applicationObject.CommandBars)的MenuBar];

        //找到的MenuBar命令栏上的工具命令栏,因为我们希望前添加
        的CommandBarControl toolsControl = menuBarCommandBar.Controls [工具];

        的CommandBarControl MYMENU;

        尝试
        {
            //获取菜单栏,如果它已经存在
            利用这项= menuBarCommandBar.Controls [我的菜单];
        }
        赶上(例外)
        {
            //犯规存在这样包装箱一个新的。
            利用这项= menuBarCommandBar.Controls.Add(类型:MsoControlType.msoControlPopup,编号:1234567890,前:toolsControl.Index  -  1);
            myMenu.Caption =我的菜单]。
        }
        返回MYMENU;
    }
 

Is it possible to create an add a custom menu to the main menu bar in Visual Studio within an Add-In?

I want the Add-In to create a company specific menu if it does not already exist and then add its own specific command to that menu. That way if multiple Add-Ins are supplied then they can all add the commands to the same menu.

I have found an msdn link for a walkthrough in creating a VSPackage which does this but not from within an Add-In and it requires its own specific installation/registration.

解决方案

    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;
    }

这篇关于添加菜单到Visual Studio菜单栏内的加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆