【问题标题】:Display custom task pane when appointment item is opened (meeting occurrence & individual meeting)打开约会项目时显示自定义任务窗格(会议发生和个人会议)
【发布时间】: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 对于这两种情况。

【问题讨论】:

    标签: c# outlook vsto


    【解决方案1】:

    不要使用AppointmentItem.Open 事件来显示任务窗格 - 使用NewInspector 事件。

    【讨论】:

    • 谢谢,我可以区分出现主和出现项。但任务窗格仅显示在日历视图上。根据文档检查器事件发生在新检查器对象创建之后但检查器窗口出现之前。 docs.microsoft.com/en-us/office/vba/api/….
    • Outlook.OlRecurrenceState rState = 约会项.RecurrenceState; if (rState == Outlook.OlRecurrenceState.olApptMaster) 返回; //Dispose 已经打开的任务窗格 (Globals.ThisAddIn.ribbonObj as Ribbon).DisposeCustomTaskPanes(); if (FindCustomId(appointmentItem.Body)) { (Globals.ThisAddIn.ribbonObj as Ribbon).edit_Cick(null); } Marshal.ReleaseComObject(appointmentItem);
    • 是的,此时检查器可能不可见,但为什么会出现问题?
    • 新添加的自定义任务窗格未放置在新的检查器窗口中。
    • 您是否将 myCustomTaskPane.Visibel 设置为 true?如何创建 myUserControl?
    【解决方案2】:

    在新检查器中,我区分主出现和出现项

    Outlook.OlRecurrenceState rState = appointmentItem.RecurrenceState;
                if (rState == Outlook.OlRecurrenceState.olApptMaster)
                    return;
                appointmentItem.Open += AppointmentItem_Open;
                (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += ThisAddIn_Close;
    

    然后在打开事件中我打开自定义任务窗格。有了这个,我能够达到预期的结果。一旦通过所有测试用例,将更新为答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 2014-02-01
      相关资源
      最近更新 更多