我正在尝试执行一项简单的任务,只要在Outlook 2010中收到新电子邮件时显示带有背景图像的表单。我可以在Outlook启动时显示该表单而没有问题,所以我认为问题是相关的我的代码识别新电子邮件。我仍然是C#的新手,所以任何帮助都会非常感激。我已经包含了以下代码。
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;
using System.Windows.Forms;
using System.Drawing;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMail += new Outlook.ApplicationEvents_11_NewMailEventHandler(ThisAddIn_NewMail);
}
void ThisAddIn_NewMail()
{
Form bam = new Form();
bam.BackgroundImage = Image.FromFile("C:\\Bam.jpg");
bam.Width = 321;
bam.Height = 613;
bam.Show();
}
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
}
答案 0 :(得分:0)
在启动事件中写入就足够了: Application.NewMail + = Application_NewMail;
我尝试使用此更改的代码,它的工作原理! 有什么问题?