将菜单添加到加载项内的 Visual Studio 菜单栏

发布于 2024-09-28 18:08:13 字数 283 浏览 0 评论 0原文

是否可以在外接程序内创建一个自定义菜单并将其添加到 Visual Studio 的主菜单栏?

我希望加载项创建公司特定菜单(如果尚不存在),然后将其自己的特定命令添加到该菜单。这样,如果提供了多个加载项,那么它们都可以将命令添加到同一菜单中。

我找到了 msdn 链接,用于创建 VSPackage 的演练但这不是来自加载项,它需要自己的特定安装/注册。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巾帼英雄 2024-10-05 18:08:13
    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;
    }
    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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文