我正在使用 VS 2010 和 Dot Net Framework 2.0。我在 Extensibility->Shared Add-ins for Outlook 中创建了一个项目。我正在尝试捕获没有被解雇的 ReplyToAll 事件。请看下面的代码:
OnConnection 方法
inspectors = applicationObject.Inspectors;
inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
void inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
mailItem = null;
try
{
Outlook.NameSpace ns = Inspector.Session;
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderInbox);
foreach (object o in inbox.Items)
{
mailItem = o as Outlook.MailItem;
if (mailItem != null)
{
break;
}
}
if (mailItem == null)
{
MessageBox.Show("Couldn't find a mail item.");
}
else
{
((Outlook.ItemEvents_10_Event)mailItem).ReplyAll += new
Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
}
}
catch (Exception ex)
{
MessageBox.Show("asdgh"+ex.StackTrace);
}
}
void Connect_ReplyAll(object Response, ref bool Cancel)
{
MessageBox.Show(Response+"Hello You have Clikced ReplyTOAll");
}
但是 Connect_ReplyAll 方法被调用了有什么问题吗?
正在运行但事件已注册的新代码
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
try
{
applicationObject = (Outlook.Application)application;
if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
addInInstance = addInInst;
inspectors = applicationObject.Inspectors;
explorer = applicationObject.Explorers.Application.ActiveExplorer();
explorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(explorer_SelectionChange);
inspectors.NewInspector += new
Outlook.InspectorsEvents_NewInspectorEventHandler(inspectors_NewInspector);
}
catch(Exception ex)
{
MessageBox.Show(""+ex.StackTrace);
}
//((Microsoft.Office.Interop.Outlook.ItemEvents_10_Event)mailItem).Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(ReplyToAllEvent);
}
void explorer_SelectionChange()
{
try
{
Outlook.MailItem mailExplorer=null;
mailTO = "";
mailCC = "";
mailBCC = "";
foreach (object selectedItem in explorer.Selection)
{
mailExplorer = selectedItem as Outlook.MailItem;
//MessageBox.Show("" + mailItem.EntryID.ToString());
break;
}
if (mailExplorer != null)
{
if (selectedItems.Contains(mailExplorer.EntryID.ToString()))
{
selectedItems.Remove(mailExplorer.EntryID);
((Outlook.ItemEvents_10_Event)mailExplorer).ReplyAll -= new Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
((Outlook.ItemEvents_10_Event)mailExplorer).Reply -= new Outlook.ItemEvents_10_ReplyEventHandler(Connect_Reply);
}
((Outlook.ItemEvents_10_Event)mailExplorer).ReplyAll +=
new Outlook.ItemEvents_10_ReplyAllEventHandler(Connect_ReplyAll);
((Outlook.ItemEvents_10_Event)mailExplorer).Reply +=
new Outlook.ItemEvents_10_ReplyEventHandler(Connect_Reply);
selectedItems.Add(mailExplorer.EntryID);
mailTO = mailExplorer.To;
mailCC = mailExplorer.CC;
mailBCC = mailExplorer.BCC;
}
}
catch(Exception ex)
{
MessageBox.Show(""+ex.StackTrace);
}
}
“一旦我使用 ReplyAll 事件注册了邮件项,如果选择了相同的邮件项,则该事件会触发多次。” 使用上面的代码解决了这个问题,但是当我分离事件时出现新错误请帮助我
我收到此错误