我有一个 Outlook 2007/2010 加载项,已成功将上下文菜单按钮添加到资源管理器。按钮本身显示正确且工作正常,但是我无法将其放置在上下文菜单上的内置控件上方,它始终添加到底部。我使用 VSTO 3.0 为 Outlook 2003 加载项创建了相同的按钮,并且相同的代码在上下文菜单顶部的“打开”按钮上方创建了一个按钮。
我的代码如下
void Application_ItemContextMenuDisplay(CommandBar CommandBar, Selection Selection)
{
if (Selection.Count != 1) return;
CommandBarControl rootButton = CommandBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, "Create Heat Call", 1, Type.Missing);
CommandBarButton button = (CommandBarButton)rootButton;
button.BeginGroup = true;
button.Tag = "CreateHeatCall";
button.Caption = "Create Heat Call";
button.Style = MsoButtonStyle.msoButtonIconAndCaption;
button.Visible = true;
button.Picture = GetImage();
button.Mask = GetImageMask();
selection = Selection;
((CommandBarButton)rootButton).Click += new _CommandBarButtonEvents_ClickEventHandler(ThisAddIn_Click);
}
我尝试过使用 CommandBar.Controls.Add() 方法的“Before”参数,但无济于事。我怀疑问题在于 ItemContextMenuDisplay 事件是在其他内置控件添加到上下文菜单之前触发的,而 Outlook 2003 加载项按钮是在由 Explorer.CommandBars 触发的方法中创建的。 VSTO 4.0 Explorer 对象中不存在的 OnUpdate 事件。
是否可以在 VSTO 4.0 for Outlook 07/10 中添加不在上下文菜单底部的按钮?