【发布时间】:2019-08-09 02:06:08
【问题描述】:
我有以下代码。当用户点击回复或回复按钮时,它将传递原始电子邮件,该电子邮件将在 SendAndComplete 按钮上进行处理。
public partial class ThisAddIn
{
public object selectedObject = null;
Outlook.MailItem mailItem = null;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = this.Application;
Outlook.Explorer currentExplorer = application.ActiveExplorer();
//Get this event fire when selection changes
currentExplorer.SelectionChange += new Outlook.ExplorerEvents_10_SelectionChangeEventHandler(CurrentExplorer_Event);
}
public void CurrentExplorer_Event()
{
if (this.Application.ActiveExplorer().Selection.Count == 1
&& this.Application.ActiveExplorer().Selection[1] is Outlook.MailItem)
{
selectedObject = this.Application.ActiveExplorer().Selection[1];
mailItem = selectedObject as Outlook.MailItem;
((Outlook.ItemEvents_10_Event)mailItem).Reply += new Outlook.ItemEvents_10_ReplyEventHandler(MailItem_Reply);
((Outlook.ItemEvents_10_Event)mailItem).ReplyAll += new Outlook.ItemEvents_10_ReplyAllEventHandler(MailItem_ReplyAll);
}
}
void MailItem_Reply(object response, ref bool cancel)
{
//No code here
}
void MailItem_ReplyAll(object response, ref bool cancel)
{
//No code here
}
}
现在selectedObject 将在按钮单击时在 Ribbon.cs 上使用。
public void SendnCompleteButton_Click(Office.IRibbonControl control)
{
Outlook.Application application = new Outlook.Application();
var addIn = Globals.ThisAddIn;
Outlook.MailItem mailItem = addIn.selectedObject as Outlook.MailItem;
MessageBox.Show(mailItem.Subject + " " + mailItem.ReceivedTime + " " + mailItem.Sender.Name)
}
消息框显示之前选择的邮件,如何释放之前选择的对象?
谢谢。
【问题讨论】:
-
“以前选择的”是什么意思?您的意思是说 SelectionChange 事件不会触发,因此您最终会得到一个旧的选择吗?
-
嗨,Dmitry,是的,SelectionChange 没有启动。由于某种原因,消息框一直显示我第一次编译时选择的第一封电子邮件。 Eugene 的建议帮助我解决了这个问题。
标签: outlook vsto outlook-addin