【问题标题】:VSTO Outlook Explorer BeforeMinimize, BeforeMaximize events won't fireVSTO Outlook Explorer BeforeMinimize,BeforeMaximize 事件不会触发
【发布时间】:2014-12-19 18:50:34
【问题描述】:

我花了最后几个小时弄清楚如何订阅任何 Outlook 资源管理器的 BeforeMinimize 和 BeforeMaximize 事件,但失败了。到目前为止我做了什么:

public partial class ThisAddIn
{
    Outlook.Explorer explorer;
    Outlook.Application application;
    Outlook.ExplorerEvents_10_BeforeMinimizeEventHandler beforeMinimizeEventHandler;

    ThisAddin_Startup()
    {
        //... create custom Task pane

        application = Globals.ThisAddIn.Application;
        explorer = application.ActiveExplorer();
        beforeMinimizeEventHandler = new Outlook.ExplorerEvents_10_BeforeMinimizeEventHandler(explorer_BeforeMinimize);
        explorer.BeforeMinimize += beforeMinimizeEventHandler;

    }

    void explorer_BeforeMinimize(ref bool Cancel)
    {
        System.Windows.Forms.MessageBox.Show("BeforeMinimize");
        Cancel = true;
    }
}

该事件永远不会被触发。我还尝试了其他方法,例如将 explorer 转换为 Outlook.ExplorerEvents_10_Event 然后订阅。我还检查了只有一个 Explorer。但是,没有任何效果。 我做错什么了吗?感谢您的帮助。

【问题讨论】:

    标签: c# .net events outlook vsto


    【解决方案1】:

    对您的代码进行了一些修改,现在我发现一切正常。

    我已经将事件处理程序直接添加到 Explorer.BeforeMinimize,而不是您添加的内容。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    
    namespace OutlookAddIn4
    {
        public partial class ThisAddIn
        {
    
            Outlook.Explorer explorer;
            Outlook.Application application;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                application = Globals.ThisAddIn.Application;
                explorer = application.ActiveExplorer();
                explorer.BeforeMinimize += explorer_BeforeMinimize;
            }
    
            void explorer_BeforeMinimize(ref bool Cancel)
            {
                System.Windows.Forms.MessageBox.Show("BeforeMinimize");
                Cancel = true;
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
    
            #endregion
        }
    }
    

    编译后,启动代码编译为

    private void ThisAddIn_Startup(object sender, EventArgs e)
    {
        this.application = Globals.ThisAddIn.Application;
        this.explorer = this.application.ActiveExplorer();
        (new ComAwareEventInfo(typeof(ExplorerEvents_10_Event), "BeforeMinimize")).AddEventHandler(this.explorer, new ExplorerEvents_10_BeforeMinimizeEventHandler(this.explorer_BeforeMinimize));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-19
      相关资源
      最近更新 更多