【问题标题】:How to add menu item to right click menu in MS Project?如何将菜单项添加到 MS Project 中的右键菜单?
【发布时间】:2012-02-03 14:16:31
【问题描述】:

我正在为Visual Studio 中的MS Project 开发一个加载项,我需要在right click menu 中的自定义菜单项。这将修改任务数据。我正在使用以下代码添加项目:

 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);

    }

对于字符串参数,我使用了所有的 ComandBar 名称:

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

它所做的只是在“插件”选项卡的功能区中添加按钮。右键菜单中没有添加任何按钮。你知道另一种添加右键菜单的方法吗?

【问题讨论】:

  • 你要看看ContextMenu

标签: c# visual-studio menu add-in right-click


【解决方案1】:

Context Menus in MS Project 看看这个链接,看看它是否会有所帮助

这是另一个处理上下文菜单的方法 Office Project adding Context Menu

此链接将解释如何在您右键单击鼠标时创建上下文菜单 Creating a Context Menu when user Right-Clicks the Mouse

【讨论】:

【解决方案2】:

您需要使用Ribbon XML API,这是您案例的示例

XML sn-p

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

功能区代码

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 2013-08-20
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多