0
votes

I am developing an add-in for MS Project in Visual Studio and I need a custom menu item in the right click menu. This will modify task data. I am using the following code to add a item:

 private void AddMenuItem(String param)
    {
        Office.MsoControlType menuItem =
            Office.MsoControlType.msoControlButton;

        btn_editor =
            (Office.CommandBarButton)app.CommandBars[param].Controls.Add
            (menuItem, missing, missing, 1, true);

        btn_editor.Style = Office.MsoButtonStyle.msoButtonCaption;
        btn_editor.Caption = "My Menu Item";
        btn_editor.Tag = "MyMenuItem";

        btn_editor.Click +=
            new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler
                (editor_Click);

    }

For String param I have used all the ComandBar names:

 CommandBars commandBars = (CommandBars)app.CommandBars;
  foreach (CommandBar cbar in commandBars)
        {
                AddMenuItem(cbar.Name);
        }

All it did, was to add the button in the Ribbon in Addins Tab. No button was added in the right click menu. Do you know another way to add in right click menu?

2
You want to look at ContextMenuMethodMan

2 Answers

1
votes

Context Menus in MS Project Take a look at this link to see if it will help

Here is another one that deals with Context Menus as well Office Project adding Context Menu

This link will explain how to get at creating a Context Menu when you Right-Click the Mouse Creating a Context Menu when user Right-Clicks the Mouse

0
votes

You'll need to use the Ribbon XML API, this is an example for your case

XML snippet

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
   <contextMenus>
      <contextMenu idMso="ContextMenuText">
         <button id="MyMenuItem" label="My Menu Item" onAction="Button_Click" />
      </contextMenu>
   </contextMenus>
</customUI>

Ribbon Code

public void Button_Click(Microsoft.Office.Core.IRibbonControl ctrl)
{
        switch (ctrl.Id)
        {
            case "MyMenuItem": System.Windows.Forms.MessageBox.Show("MyMenuItem"); break;
        }
}