Outlook VSTO处理SelectionChange正确(当前doubleclick使Addin崩溃) [英] Outlook VSTO Handling SelectionChange correctly (currently doubleclick crashes Addin)

查看:92
本文介绍了Outlook VSTO处理SelectionChange正确(当前doubleclick使Addin崩溃)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,您需要跟踪浏览器的激活和停用.在激活期间,您需要为当前资源管理器添加SelectionChange事件处理程序. 对于单击AppointmentItems而言,这似乎非常合适.但是,双击约会系列并选择一个约会时,Addin崩溃.

From what I understand you need to track Activation and Deactivation of the Explorers. During activation, you need to add SelectionChange event handlers for the current explorer. This seems to work perfectly for single clicks on AppointmentItems. But it crashes the Addin when double-clicking on an appointment series and selecting a single Appointment.

以下是来源: 在班级

    private Outlook.Explorer currentExplorer = null;
    private Outlook.AppointmentItem currentAppointmentItem = null;

在启动内:

       currentExplorer = this.Application.ActiveExplorer();

        ((Outlook.ExplorerEvents_10_Event)currentExplorer).Activate +=
        new Outlook.ExplorerEvents_10_ActivateEventHandler(
        Explorer_Activate);

        currentExplorer.Deactivate += new
        Outlook.ExplorerEvents_10_DeactivateEventHandler(
        Explorer_Deactivate);

事件处理程序:

    void Explorer_Activate()
    {
        currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(Selection_Change);
    }

    void Explorer_Deactivate()
    {
        currentExplorer.SelectionChange -= new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(Selection_Change); ;
    }

    private void Close_Explorer()
    {

    }

    private void Selection_Change()
    {
        Outlook.MAPIFolder selectedFolder = currentExplorer.CurrentFolder;            
        if (currentExplorer.Selection.Count > 0)
        {
            Object selObject = currentExplorer.Selection[1];
            if (selObject is Outlook.AppointmentItem)
            {
                currentAppointmentItem = (Outlook.AppointmentItem)selObject;
            }
            else
            {
                currentAppointmentItem = null;
            }
        }
    }

我忽略了什么?注销的形式有问题吗?

What am I overlooking? Is the form of deregistering a problem?

推荐答案

激活或停用资源管理器后,无需添加和删除事件处理程序.您是否要支持多个浏览器?在这种情况下,创建一个包装类,将Explorer对象保留为其成员,并将其方法用作事件处理程序.

You do not need to add and remove event handlers as an explorer is activated / deactivated. Are you trying to support multiple explorers? In that case, create a wrapper class that hold the Explorer object as it member and uses its methods as event handlers.

这篇关于Outlook VSTO处理SelectionChange正确(当前doubleclick使Addin崩溃)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆