【发布时间】:2019-08-06 14:56:48
【问题描述】:
我在我发送的会议邀请中嵌入了一些文本。当用户从包含我指定的文本的日历中打开约会时,我想启动一个自定义任务窗格。
我正在使用 InspectorsEvents_NewInspectorEventHandler 来获取打开事件并检查约会项目是否已打开。在预约的情况下,我调用代码来显示自定义任务窗格。
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.AppointmentItem appointmentItem = Inspector.CurrentItem as Outlook.AppointmentItem;
if (appointmentItem != null)
{
(appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Open += _appointment_Open;
(appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += ThisAddIn_Close;
}
}
private void _appointment_Open(ref bool Cancel)
{
if ((Globals.ThisAddIn.ribbonObj as Ribbon) != null && (Globals.ThisAddIn.ribbonObj as Ribbon).IsLoggedOn)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.AppointmentItem)
{
Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem);
//Without display() the taskpane is displayed on the calendar screen
apptItem.Display();
//Dispose already open task panes
(Globals.ThisAddIn.ribbonObj as Ribbon).DisposeCustomTaskPanes();
if (FindCustomId(apptItem.Body))
{
(Globals.ThisAddIn.ribbonObj as Ribbon).edit_Cick(null);
}
}
Marshal.ReleaseComObject(selObject);
}
}
edit_click()
{
CustomTaskPane myCustomTaskPane =
Globals.ThisAddIn.CustomTaskPanes.Add(myUserControl, "edit pane");
}
通过使用 apptItem.Display(); 约会被打开,然后任务窗格仅显示打开的项目。如果未使用 display(),则任务窗格在 Outlook 的日历视图中打开,而不是在打开的项目上。
当我打开和重复项目时,会出现这种方法的问题。如果我打开“仅此一个”项目,那么该场景工作正常。但是,如果我打开“打开整个系列”,那么 open() 事件会被触发两次并打开两个窗口,一个与会议发生有关,另一个与会议系列有关。如果我删除 display() 方法调用,“打开系列”将只打开一个窗口。
我的目标是避免在用户打开会议系列时打开自定义任务窗格。仅当用户打开会议事件或单个会议时才会显示任务窗格。 此外,有没有办法区分约会何时作为会议发生或会议系列打开。在 open_event 我得到 Appointment.RecurrenceState 作为 olApptOccurrence 对于这两种情况。
【问题讨论】: