在我的 VSTO Outlook 插件中,我试图放置一个按钮,当我右键单击文件夹时会显示该按钮。在我的启动功能中我有这个:
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);
}
最后是点击处理程序......
void contextButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
//stuff here
}
我的问题是如何发送MAPIFolder Folder
from myApp_FolderContextMenuDisplay
to contextButton_Click
?
(如果这可以通过其他方式完成,我也欢迎建议)
最简单的方法就是使用闭包,例如:
// 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。)
快乐编码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)