如何在 MS Project 中添加菜单项到右键菜单?
我正在 Visual Studio
中为 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);
}
它所做的就是在 Addins 选项卡的功能区中添加按钮。右键菜单中没有添加任何按钮。您知道添加右键菜单的另一种方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MS Project 中的上下文菜单
看一下这个链接,看看它是否有帮助
这是另一个也处理上下文菜单的链接
Office 项目添加上下文菜单
此链接将解释如何在右键单击鼠标时创建上下文菜单
用户右键单击时创建上下文菜单鼠标
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
您需要使用
nofollow noreferrer">功能区 XML API,这是您的案例XML 片段
功能区代码
You'll need to use the Ribbon XML API, this is an example for your case
XML snippet
Ribbon Code