文件夹上的C#(outlook加载项)上下文菜单
在我的VSTO outlook插件中,我试图放置一个按钮,当我右键单击文件夹时,该按钮将显示出来。在我的启动功能中,我有:文件夹上的C#(outlook加载项)上下文菜单,c#,events,outlook,C#,Events,Outlook,在我的VSTO outlook插件中,我试图放置一个按钮,当我右键单击文件夹时,该按钮将显示出来。在我的启动功能中,我有: Outlook.Application myApp = new Outlook.ApplicationClass(); myApp.FolderContextMenuDisplay += new ApplicationEvents_11_FolderContextMenuDisplayEventHandler(myApp_FolderContextMenuDisplay);
Outlook.Application myApp = new Outlook.ApplicationClass();
myApp.FolderContextMenuDisplay += new ApplicationEvents_11_FolderContextMenuDisplayEventHandler(myApp_FolderContextMenuDisplay);
然后我有了处理这个问题的人
void myApp_FolderContextMenuDisplay(CommandBar commandBar, MAPIFolder Folder)
{
var contextButton = commandBar.Controls.Add(MsoControlType.msoControlButton, missing, missing, missing, true) as CommandBarButton;
contextButton.Visible = true;
contextButton.Caption = "some caption...";
contextButton.Click += new _CommandBarButtonEvents_ClickEventHandler(contextButton_Click);
}
最后是click的处理程序
void contextButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
//stuff here
}
我的问题是如何将MAPIFolder文件夹
从myApp\u FolderContextMenuDisplay
发送到contextButton\u单击
(如果这可以用另一种方法完成,我也愿意听取建议)最简单的方法就是使用闭包,例如:
// where Folder is a local variable in scope, such as code in post
contextButton.Click += (CommandBarButton ctrl, ref bool cancel) => {
DoReallStuff(ctrl, Folder, ref cancel);
};
如果需要,确保清理事件。需要注意的一点是,文件夹的RCW现在可能有一个“延长的生存期”,因为关闭可能会使其保持比以前更长的生存期(但对于OOM,在不需要时手动释放RCW是非常重要的)
快乐编码