假设你使用Visual Studio 2010中,您最有可能开始创建插件-在。有关VSTO和Visual Studio的详细信息,请参阅here。
一旦启动并运行后,您将拥有一个名为ThisAddIn.cs的源文件,其中包含加载项中的“主入口点”。从那里,你可以将事件发生在Outlook将会在某些事件发生时引发的事件中。您将最有可能感兴趣的下列事件:
- BeforeFolderSwitch
- FolderSwitch
您的代码将是这个样子:
private void ThisAddIn_Startup(object sender, EventArgs e)
{
var explorer = this.Application.ActiveExplorer();
explorer.BeforeFolderSwitch += new ExplorerEvents_10_BeforeFolderSwitchEventHandler(explorer_BeforeFolderSwitch);
explorer.FolderSwitch += new ExplorerEvents_10_FolderSwitchEventHandler(explorer_FolderSwitch);
}
/// <summary>
/// Handler for Outlook's "BeforeFolderSwitch" event. This event fires before the explorer goes to
/// a new folder, either as a result of user action or through program code.
/// </summary>
/// <param name="NewlySelectedFolderAsObject">
/// The new folder to which navigation is taking place. If, for example, the user moves from "Inbox"
/// to "MyMailFolder", the new current folder is a reference to the "MyMailFolder" folder.
/// </param>
/// <param name="Cancel">
/// A Boolean describing whether or not the operation should be canceled.
/// </param>
void explorer_BeforeFolderSwitch(object NewlySelectedFolderAsObject, ref bool Cancel)
{
if (NewlySelectedFolderAsObject == null)
return;
var newlySelectedFolderAsMapiFolder = NewlySelectedFolderAsObject as MAPIFolder;
}
void explorer_FolderSwitch()
{
}
你的代码应该放在那些事件处理程序来执行您的工作。