C#Outlook加载项约会事件';ItemSend';不能正确地取消
我正在使用C#开发一个小Outlook加载项,但我无法使此加载项正确取消ItemSend过程。 我在此想到以下情景: 考虑这个小插件:C#Outlook加载项约会事件';ItemSend';不能正确地取消,c#,outlook,add-in,C#,Outlook,Add In,我正在使用C#开发一个小Outlook加载项,但我无法使此加载项正确取消ItemSend过程。 我在此想到以下情景: 考虑这个小插件: private void ThisAddIn_Startup(object sender, System.EventArgs e) { ((Outlook.ApplicationEvents_Event)this.Application).ItemSend += new ApplicationEvents_ItemSendEven
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已接受您对约会项目所做的更改
这是故意的行为吗?即使取消参数已更改为“true”,Outlook是否仍可以停止保存更改?您也可以使用事件并锁定事件
根据AppointItem.Send
MSDN文档-预期的行为是当Cancel=true
时,发送不会发生,inspector窗口保持打开,更改仍然保存-只是不会发送给与会者
如果要取消保存-在发送之前,您需要锁定事件以取消保存。是否存在某些ItemSending事件?ItemSend看起来像是发送实际项目后的操作。很遗憾,这是Microsoft.Office.Interop.Outlook.ApplicationEvents\u事件中唯一可以访问的与“发送”相关的事件,该事件将适用于所有项目,不幸的是,我需要事件处理方法中的AppointmentItem来验证它。AppointmentItem.Write只有一个参数,即它的ref bool cancel。您只需要在包装类中存储对它的引用。请看下面的图片。您需要保留一个属性引用。