不久前,我使用 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
事件。但微软告诉我这样的事件应该存在:
但是,Visual Studio 告诉我只有一个 Close()
方法。
我错过了一些东西,但是什么?
最佳答案
您需要将上面的 OutlookExplorer 变量转换为 ExplorerEvents
接口(interface)。
关于c# - VSTO Outlook 插件 : Cannot use Explorer Close event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49174854/