问题描述
在我的VSTO outlook addin中,我试图放一个按钮,当我右键单击一个文件夹时会出现。在我的启动功能我有这样的:
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)作为CommandBarButton;
contextButton.Visible = true;
contextButton.Caption =some caption ...;
contextButton.Click + = new _CommandBarButtonEvents_ClickEventHandler(contextButton_Click);
}
,最后是点击的处理程序....
void contextButton_Click(CommandBarButton Ctrl,ref bool CancelDefault)
code> myApp_FolderContextMenuDisplay to
{
//这里
}
我的问题是如何发送MAPIFolder文件夹
contextButton_Click
?
(如果可以完成
解决方案最简单的方法只是使用一个闭包,例如: p>
//其中Folder是范围内的局部变量,例如post
中的代码bBBBBTBTtonton.Click + =(CommandBarButton ctrl ,ref bool cancel)=> {
DoReallStuff(ctrl,Folder,ref cancel);
};
如果需要,请务必清理事件。需要注意的一件事是,文件夹的RCW现在可能具有延长使用寿命,因为关闭可能比以前保持活动更长(但是OOM是非常重要的来手动释放不需要RCW)。
快乐编码。
In my VSTO outlook addin I'm trying to put a button that will show up when i right click on a folder. In my Startup function I have this:
Outlook.Application myApp = new Outlook.ApplicationClass(); myApp.FolderContextMenuDisplay += new ApplicationEvents_11_FolderContextMenuDisplayEventHandler(myApp_FolderContextMenuDisplay);
then i have the handler for that...
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); }
and finally the handler for click....
void contextButton_Click(CommandBarButton Ctrl, ref bool CancelDefault) { //stuff here }
My question is how do I send that
MAPIFolder Folder
frommyApp_FolderContextMenuDisplay
tocontextButton_Click
?(If this can be done another way, I'm open for suggestions too)
解决方案Easiest way is just to use a closure, for example:
// 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); };
Make sure to clean up the event, if required. One thing to watch out for is that the RCW for the Folder may now have an "extended lifetime" as the closure may keep it alive longer than before (but with the OOM is is very important to manually release the RCWs when not needed.)
Happy coding.
这篇关于文件夹上的C#(outlook加载项)上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!