是否可以在外接程序内创建一个自定义菜单并将其添加到 Visual Studio 的主菜单栏?
我希望加载项创建公司特定菜单(如果尚不存在),然后将其自己的特定命令添加到该菜单。这样,如果提供了多个加载项,那么它们都可以将命令添加到同一菜单中。
我找到了一个msdn链接有关创建 VSPackage 的演练,该 VSPackage 会执行此操作,但不是从外接程序内部进行,并且它需要自己的特定安装/注册。
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)