【问题标题】:C# Outlook AddIn Appointment event 'ItemSend' does not cancel properlyC# Outlook AddIn Appointment 事件“ItemSend”未正确取消
【发布时间】:2012-04-19 21:04:25
【问题描述】:

我正在使用 C# 开发一个小的 Outlook 插件,但我无法让这个插件正确地取消 ItemSend 进程。 我在此考虑以下情况: 考虑一下这个小插件:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        ((Outlook.ApplicationEvents_Event)this.Application).ItemSend += new ApplicationEvents_ItemSendEventHandler(ThisAddIn_ItemSend);
    }

    void ThisAddIn_ItemSend(object Item, ref bool Cancel)
    {
        System.Windows.Forms.MessageBox.Show("You can't save it, it's in the past!");
        Cancel = true;
        return;
    }

现在,当我尝试更改现有约会项目时,我会在约会窗口中打开它时更改它的一些值,例如位置等。点击约会窗口中的“发送”按钮时,文本框中的消息出现如预期。但问题是 Outlook 会忽略此取消并已保存更改。唯一发生的事情是约会窗口没有关闭。但是,如果只是关闭窗口而不显式保存,您可以看到 Outlook 已经接受了您对约会项目所做的更改。

这是一种预期的行为吗?即使 Cancel 参数已更改为“true”,是否可以阻止 Outlook 保存更改?

【问题讨论】:

  • 不是有一些 ItemSending 事件吗? ItemSend 看起来像是发送实际项目后的一个操作。
  • 不幸的是,这是唯一可以在 Microsoft.Office.Interop.Outlook.ApplicationEvents_Event 中访问的与“发送”相关的事件,它适用于所有项目,就我目前所见。跨度>

标签: c# outlook add-in


【解决方案1】:

您也可以使用Application.Inspectors.NewInspector 事件并锁定AppointmentItem.Send 事件。

根据AppointmentItem.Send MSDN 文档 - 预期的行为是当Cancel = true 时发送不会发生,检查器窗口保持打开状态并且更改仍然保存 - 只是没有发送给与会者。

如果您想取消保存 - 您需要在发送前锁定 AppointmentItem.Write 事件以取消保存。

【讨论】:

  • 不幸的是,我需要事件处理方法中的 AppointmentItem 才能对其进行验证。 AppointmentItem.Write 只有一个参数,它的 ref bool cancel。
  • 您只需要将对它的引用存储在包装类中。看看InspectorWrapper howto。您需要保留一个属性参考。
猜你喜欢
  • 1970-01-01
  • 2012-08-24
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2017-08-19
  • 2017-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多