C# 如何在我的加载项菜单中添加几个选项?
我真的很挣扎。我想在“工具”菜单中创建一个项目,以便C# 如何在我的加载项菜单中添加几个选项?,c#,visual-studio-2010,visual-studio-addins,C#,Visual Studio 2010,Visual Studio Addins,我真的很挣扎。我想在“工具”菜单中创建一个项目,以便 tools --> myaddin --> my option 1 --> my option 2 --> my option 3 我就是想不出我打算怎么做。这真的很烦人,没有关于它的信息,似乎只是讨论如何添加项目 我已经拥有的代码是addin库创建的 public void OnConnection(object applicati
tools --> myaddin --> my option 1
--> my option 2
--> my option 3
我就是想不出我打算怎么做。这真的很烦人,没有关于它的信息,似乎只是讨论如何添加项目
我已经拥有的代码是addin库创建的
public void OnConnection(object application, ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if(connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object []contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
//Place the command on the tools menu.
//Find the MenuBar command bar, which is the top-level command bar holding all
// the main menu items:
Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar =
((Microsoft.VisualStudio.CommandBars.CommandBars)
_applicationObject.CommandBars)["MenuBar"];
//Find the Tools command bar on the MenuBar command bar:
CommandBarControl toolsControl = menuBarCommandBar.Controls["Tools"];
//same thing just as a popup
CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;
//This try/catch block can be duplicated if you wish to add multiple commands to
// be handled by your Add-in,
// just make sure you also update the QueryStatus/Exec method to include the new
// command names.
try
{
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(_addInInstance, "Switch",
"Switch", "Executes the command for Switch", true, 59, ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported+
(int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the tools menu:
if((command != null) && (toolsPopup != null)) {
command.AddControl(toolsPopup.CommandBar, 1);
}
}
catch(System.ArgumentException)
{
//If we are here, then the exception is probably because a command with that
// name
// already exists. If so there is no need to recreate the command and we can
// safely ignore the exception.
}
}
}
使用GUI builder时,将鼠标悬停在菜单项上并键入它们的名称:
打开菜单->将鼠标悬停在菜单项上->单击出现的框->键入菜单项文本->键入下一个菜单项文本。这不是表单应用程序,没有菜单项对象:-(
menuItem.DropDownItems.AddRange(new ToolStrinpItem[] { menuItem1, menuItem2 });