我想在上下文菜单中右键单击它并单击自定义按钮时获取当前选定的嵌入式附件对象。
这些是我到目前为止所做的步骤:
为 ContextMenuInlinePicture 功能区上下文菜单添加了自定义按钮
<customUI ...> <contextMenus> <contextMenu idMso="ContextMenuInlinePicture"> <button id="SendInlinePictureToHbbButton" label="Send to HBB" onAction="OnSendInlinePictureToHbbButtonClick" /> </contextMenu> </contextMenus> </customUI>
通过右键单击它,我正在调用我的函数 OnSendInlinePictureToHbbButtonClick:
public void OnSendInlinePictureToHbbButtonClick(IRibbonControl control) { var msg = "OnSendMailToHbbButtonClick \n\n"; if (control.Context is Explorer) { msg = "Context=Explorer \n"; var explorer = control.Context as Explorer; if (explorer.AttachmentSelection.Count >= 1) { msg += "AttachmentSelection \n"; msg = explorer.AttachmentSelection .Cast<Attachment>() .Aggregate(msg, (current, attach) => current + attach.DisplayName + "\n"); } else { var selection = explorer.Selection; msg += "MailItemSelection \n"; if (selection.Count == 1) { var olItem = new OutlookItem(selection[1]); msg = msg + olItem.Subject + "\n" + olItem.LastModificationTime; } else { msg = msg + "Multiple Selection Count=" + selection.Count; } } } MessageBox.Show(msg); }
运行加载项时,我可以在右键单击嵌入图像/附件时看到自定义上下文菜单项。
- 单击该按钮后,运行上述方法,但我无法获得“AttachmentSelection”。相反,我得到“MailItemSelection”。
- 我怎样才能让附件对象用户右键单击,所以我可以使用它?