【问题标题】:How to get Outlook Appointment from ContextMenu如何从 ContextMenu 获取 Outlook 约会
【发布时间】:2015-01-25 23:22:36
【问题描述】:

我已将 ContextMenuItem 添加到 Outlook 约会的 ContextMenu。

问题是我无法弄清楚如何获取 Appointment 对象。如果我得到一个 IRibbonControl,它的 Context 属性应该包含 Appointment,但它包含一个 Selection。据我所知,我无法使用“选择”到达约会。

这个页面是我来自的地方:https://msdn.microsoft.com/en-us/library/office/ff863278%28v=office.14%29.aspx

有人知道怎么预约吗?

【问题讨论】:

    标签: c# .net outlook ms-office outlook-addin


    【解决方案1】:

    Selection 对象包含在图片上选择的 AppointmentItem 对象。例如:

                    Object selObject = Selection[1];
                    if (selObject is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem =
                            (selObject as Outlook.MailItem);
                        itemMessage = "The item is an e-mail message." +
                            " The subject is " + mailItem.Subject + ".";
                        mailItem.Display(false);
                    }
                    else if (selObject is Outlook.ContactItem)
                    {
                        Outlook.ContactItem contactItem =
                            (selObject as Outlook.ContactItem);
                        itemMessage = "The item is a contact." +
                            " The full name is " + contactItem.Subject + ".";
                        contactItem.Display(false);
                    }
                    else if (selObject is Outlook.AppointmentItem)
                    {
                        Outlook.AppointmentItem apptItem =
                            (selObject as Outlook.AppointmentItem);
                        itemMessage = "The item is an appointment." +
                            " The subject is " + apptItem.Subject + ".";
                    }
                    else if (selObject is Outlook.TaskItem)
                    {
                        Outlook.TaskItem taskItem =
                            (selObject as Outlook.TaskItem);
                        itemMessage = "The item is a task. The body is "
                            + taskItem.Body + ".";
                    }
                    else if (selObject is Outlook.MeetingItem)
                    {
                        Outlook.MeetingItem meetingItem =
                            (selObject as Outlook.MeetingItem);
                        itemMessage = "The item is a meeting item. " +
                             "The subject is " + meetingItem.Subject + ".";
                    }
    

    更多信息请参见How to: Programmatically Determine the Current Outlook Item

    【讨论】:

    • 不得使用Explorer.Selection 集合。看我的回答。
    • Dmitry,其实我不建议使用 Explorer 对象。 IRibbonControl 的 Context 属性用于根据初始帖子中显示的代码获取一个 Selection 对象。您为什么想到 Explorer?
    • 您回复中的链接使用 Explorer.Selection。
    • 它只是描述了 Selection 对象...无论如何,我认为作者知道如何获取 Selection 对象的正确方法。
    【解决方案2】:

    不要在弹出菜单事件处理程序中使用 Explorer.Selection - 可以选择一条消息,然后右键单击另一条消息而不选择它。 Explorer.Selection 集合不会改变,Explorer.SelectionChange 事件也不会触发。

    当您处理事件处理程序时,Context 参数将传递给您。将其转换为 Selection 对象并使用它。该集合将不同于 Explorer.Selection 对象。

    【讨论】:

    • 代码中使用IRibbonControl.Context属性来获取Selection对象。
    • 在哪里?我在原始问题或您的回答中没有看到它。
    • 看看 SendToGoogle 方法。
    • 抱歉,我可能是盲人 - 您在 SendToGoogle 中究竟看到了什么?
    • IRibbonControl.Context 属性用于获取 Selection 对象。我错了吗?
    猜你喜欢
    • 2015-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-25
    • 2010-12-14
    相关资源
    最近更新 更多