0
上的Outlook插件在工作,到目前为止按预期工作的一切: - 外接负载 - 创建一个组合框和更改事件处理程序 - 创建时的事件处理程序用户点击新电子邮件在Outlook如何重置事件外接
取决于用户在组合框中选择的内容,将加载HTML模板或白色模板(仅返回原始状态)。
经过几次测试在两个模板之间来回切换之后,变化事件不再被捕获。你可以在代码中看到下面我使用它来办理变更事件:
cmboBxKeyWord.Change += new CommandBarComboBoxEvents_ChangeEventHandler(cmboBxKeyWord_Change);
这里是代码的其余部分:
public partial class ThisAddIn
{
private string templateName = "";
private string subject="";
private int messageType;
private string customerId;
private CommandBar menuBar;
private Outlook.Inspectors inspectors;
StringBuilder sb = new StringBuilder();
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
CreateControl();
inspectors = this.Application.Inspectors;
inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
private void CreateControl(){
menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
CommandBarComboBox cmboBxKeyWord = (Office.CommandBarComboBox)menuBar.Controls.Add(Office.MsoControlType.msoControlComboBox, missing, missing, 1, true);
cmboBxKeyWord.AddItem("Template Email");
cmboBxKeyWord.AddItem("Regular Email");
cmboBxKeyWord.Change += new _CommandBarComboBoxEvents_ChangeEventHandler(cmboBxKeyWord_Change);
}
private void cmboBxKeyWord_Change(CommandBarComboBox Ctrl)
{
this.messageType = Ctrl.ListIndex - 1;
if (this.messageType == 1)
{
this.templateName = @"c:\templates\Blank Email.txt";
}
else
{
this.templateName = @"c:\templates\Template Email.txt";
this.customerId = Microsoft.VisualBasic.Interaction.InputBox("Enter Customer ID of the customer to which you want to send this email", "Customer ID");
if (this.customerId == null || this.customerId.Length == 0)
this.messageType = 1;
}
}
private void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
if (mailItem != null)
{
if (mailItem.EntryID == null)
{
if (this.messageType == 0) //HTML template email not the blank email...
{
mailItem.HTMLBody = getBody(); // the get body is a func that returns string, after fetching data from DB and processing it...nothing magic
mailItem.Subject = getSubject();
}
else
{
mailItem.HTMLBody = "";
mailItem.Subject = "";
}
}
}
}
}
我怀疑我的事件处理程序,我的想法是代码保持运行,事件处理程序总是被添加(+ =)永远不会被删除( - =)我只是假设这是因为我的委托/事件处理程序的一点经验。由于