[英]VSTO Outlook Explorer BeforeMinimize, BeforeMaximize events won't fire
I spent the last hours figuring out how to subscribe to any Outlook explorer's BeforeMinimize and BeforeMaximize Events and failed. 我花了最后几个小时弄清楚如何订阅任何Outlook资源管理器的BeforeMinimize和BeforeMaximize事件,但是失败了。 What I did so far:
到目前为止,我做了什么:
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;
}
}
The event never gets fired. 该事件永远不会被解雇。 I also tried other approaches like casting
explorer
to Outlook.ExplorerEvents_10_Event
and then subscribing. 我还尝试了其他方法,例如将
explorer
投射到Outlook.ExplorerEvents_10_Event
然后进行订阅。 I also checked that there is just one Explorer. 我还检查了只有一个资源管理器。 Nothing works, though.
但是,没有任何效果。 Am I doing anything wrong?
我做错什么了吗? Thank you for your help.
谢谢您的帮助。
Did a little modification with your code and I have found everything working now. 对您的代码进行了一些修改,现在我发现一切正常。
I have added Event Handler to Explorer.BeforeMinimize directly, instead of what you have added. 我已经将事件处理程序直接添加到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
}
}
After compilation, the startup code is compiled to 编译后,启动代码被编译为
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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.