2012-04-29 2 views
0

Im действительно борется с этим. Я хочу, чтобы создать элемент в меню инструментов, так что у меня есть ...Как добавить несколько вариантов в мое меню добавления?

tools --> myaddin --> my option 1 
        --> my option 2 
        --> my option 3 

я просто не могу работать, как Im хотел сделать это. Его действительно раздражает там не на самом деле информацию о нем, что кажется просто идти над тем, как добавить элементы ...

код у меня уже есть то, что создает библиотеку Аддин ....

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

ответ

0
menuItem.DropDownItems.AddRange(new ToolStrinpItem[] { menuItem1, menuItem2 }); 

И используя конструктор GUI работает, зависая над пунктами меню и введя их имена: Откройте меню -> наведите указатель мыши на элемент меню -> щелкните появившееся окно -> введите текст элемента меню -> введите в следующий текст пункта меню.

+0

это не приложение формы, нет объекта menuItem :-( – Exitos

 Смежные вопросы

  • Нет связанных вопросов^_^