【发布时间】: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