c# - VSTO Outlook 插件 : Cannot use Explorer Close event

标签 c# vsto office-interop outlook-addin

不久前,我使用 NetOffice 编写了一个 Outlook AddIn,效果非常好。现在,借助新的 Visual Studio Community 2017,我可以在没有 NetOffice 帮助的情况下对 Office AddIn 进行编程。所以我想更改我的代码,但遇到了一个问题:我无法订阅 Explorer.Close 事件:

using Outlook = Microsoft.Office.Interop.Outlook;
namespace OLTest2
{
    public class ExplorerHandle
    {
        private Outlook.Explorer OutlookExplorer;
        public void InitExplorer(Outlook.Explorer expl)
        {
            OutlookExplorer = expl;
            // The next two lines compile:
            OutlookExplorer.BeforeItemPaste += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChange += SelectionChangeEvent;

            // ***Next line does not compile***:
            OutlookExplorer.Close += CloseEvent; // "Cannot assign to 'Close' because it is a 'method group'"
            
            // This is the old NetOffice code which worked fine:
            /* 
            OutlookExplorer.BeforeItemPasteEvent += BeforeItemPasteEvent;
            OutlookExplorer.SelectionChangeEvent += SelectionChangeEvent;
            OutlookExplorer.CloseEvent += CloseEvent; 
            */ 
        }
    }
}

IntelliSense 没有向我显示 Outlook.Explorer 对象是否存在 Close 事件。但微软告诉我这样的事件应该存在:

Explorer events on MSDN

但是,Visual Studio 告诉我只有一个 Close() 方法。

我错过了一些东西,但是什么?

最佳答案

您需要将上面的 OutlookExplorer 变量转换为 ExplorerEvents 接口(interface)。

关于c# - VSTO Outlook 插件 : Cannot use Explorer Close event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49174854/

相关文章:

C# Excel Reader 将时间戳转为十进制数

C# listview 子项不显示

c# - 我应该使用转换类吗?

c# - Word VSTO - 向 Word 文件添加标签

outlook - 即使我在 Item_Write 中设置了取消,也会发送 session 通知

.net - Excel 对象模型的文档

.net - 为什么我们激活它时Word没有 "come to front"?

c# - 安装 Enterprise Lib 5.0 后找不到 Microsoft.Practices.ObjectBuilder2.dll

c# - 从 char[] 创建不安全的字符串

c# - 使用c#删除书签的内容而不删除ms word中的书签