Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
文件夹上的C#(outlook加载项)上下文菜单_C#_Events_Outlook - Fatal编程技术网

文件夹上的C#(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);

在我的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);
}
最后是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是非常重要的)

快乐编码