C# 如何在MS Project中将菜单项添加到右键单击菜单?
我正在为C# 如何在MS Project中将菜单项添加到右键单击菜单?,c#,visual-studio,menu,add-in,right-click,C#,Visual Studio,Menu,Add In,Right Click,我正在为visualstudio中的MS Project开发一个外接程序,我需要在右键单击菜单中设置一个自定义菜单项。这将修改任务数据。我正在使用以下代码添加项目: private void AddMenuItem(String param) { Office.MsoControlType menuItem = Office.MsoControlType.msoControlButton; btn_editor =
visualstudio
中的MS Project
开发一个外接程序,我需要在右键单击菜单中设置一个自定义菜单项。这将修改任务数据。我正在使用以下代码添加项目:
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);
}
它所做的只是在“加载项”选项卡的功能区中添加按钮。在右键单击菜单中未添加任何按钮。您知道添加右键单击菜单的其他方法吗?
看看这个链接,看看它是否有帮助
这是另一个处理上下文菜单的
此链接将解释如何在右键单击鼠标时创建上下文菜单
您需要使用,这是您案例的一个示例
XML片段
您需要查看ContextMenuI,以便将菜单项添加到MS Project的右键单击菜单。我无法创建新的上下文菜单。它在外接程序应用程序上不起作用。这个链接也有一些例子
<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;
}
}