我正在为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);
}它所做的一切,就是将按钮添加到功能区的加载项选项卡中。右键菜单中未添加任何按钮。你知道另外一种添加右键菜单的方法吗?
发布于 2012-02-03 22:22:45
Context Menus in MS Project请查看此链接以查看是否有帮助
这是另一个处理上下文菜单的Office Project adding Context Menu
此链接将解释如何在右键单击鼠标Creating a Context Menu when user Right-Clicks the Mouse时创建上下文菜单
发布于 2018-07-16 04:01:46
您将需要使用Ribbon XML API,这是针对您的情况的示例
XML代码片段
<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;
}
}https://stackoverflow.com/questions/9130010
复制相似问题