C# 用户单击关闭消息窗口时发生的事件

C# 用户单击关闭消息窗口时发生的事件,c#,outlook,vsto,outlook-addin,C#,Outlook,Vsto,Outlook Addin,是否有办法知道用户何时单击关闭消息窗口,并且在显示“是否要保存更改”对话框之前?我已注册到Inspector.Close事件,但它仅在用户决定保存/放弃更改后激发: ((InspectorEvents\u 10\u Event)Inspector).Close+=OnInspector Close好的,显然我需要使用来自邮件项目的事件,而不是检查器。我需要在内部注册处理程序,例如NewInspector处理程序: if (inspector.CurrentItem is MailItem) {

是否有办法知道用户何时单击关闭消息窗口,并且在显示“是否要保存更改”对话框之前?我已注册到Inspector.Close事件,但它仅在用户决定保存/放弃更改后激发:
((InspectorEvents\u 10\u Event)Inspector).Close+=OnInspector Close

好的,显然我需要使用来自邮件项目的事件,而不是检查器。我需要在内部注册处理程序,例如NewInspector处理程序:

if (inspector.CurrentItem is MailItem)
{
  MailItem item = inspector.CurrentItem as MailItem;
  ((ItemEvents_10_Event)item).Close += OnItemClose;
}
然后准备处理程序:

private void OnItemClose(ref bool cancel) //ItemEvents_10_CloseEventHandler
{
  ((ItemEvents_10_Event)_lastOpenedItem).Close -= OnItemClose;
  _lastOpenedItem.Close(OlInspectorClose.olDiscard);
}

并且此OnItemClose将在Inspector的关闭事件激发(
((InspectorEvents\u 10\u event)Inspector)之前执行。关闭(
)。

好的,因此显然我需要使用邮件项目中的事件,而不是Inspector。我需要在内部注册处理程序,例如NewInspector处理程序:

if (inspector.CurrentItem is MailItem)
{
  MailItem item = inspector.CurrentItem as MailItem;
  ((ItemEvents_10_Event)item).Close += OnItemClose;
}
然后准备处理程序:

private void OnItemClose(ref bool cancel) //ItemEvents_10_CloseEventHandler
{
  ((ItemEvents_10_Event)_lastOpenedItem).Close -= OnItemClose;
  _lastOpenedItem.Close(OlInspectorClose.olDiscard);
}

这个OnItemClose将在Inspector的关闭事件触发(
((InspectoreEvents\u 10\u event)Inspector)之前执行。关闭(/code>)。

我看到了,但看不出它是如何解决我的问题的。只是想一想:保存消息似乎会阻止对话框显示(它仅在邮件项存在未保存的更改时显示)。您可以在关闭事件触发后删除它。嗯,出于安全原因,我无法保存邮件,但我想我不能用Outlook做更多的事情(我想没有“CloseStarted”事件?)。谢谢你的提示!我想看看是否有类似于QueryClose事件的事件(这是一个基本上在实际演示之前触发的PowerPoint演示文稿事件。关闭事件…)但是看起来没有。我已经看到了,但看不出它是如何解决我的问题的。只是想一想:保存消息似乎会阻止对话框显示(它只在邮件项存在未保存的更改时显示)。您可以在关闭事件触发后将其删除。嗯,出于安全原因,我无法保存该邮件,但我想我不能用Outlook做更多的事情(我想没有“CloseStarted”事件?)。不过,感谢您的提示!我想看看是否有类似于QueryClose事件的事件(这是一个PowerPoint演示文稿事件,基本上在实际演示文稿之前触发。关闭事件…)但看起来没有。