文件夹上的C#(outlook加载项)上下文菜单 [英] C# (outlook add-in) context menu on folders

查看:178
本文介绍了文件夹上的C#(outlook加载项)上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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)
{
//这里
}
我的问题是如何发送 MAPIFolder文件夹
code> myApp_FolderContextMenuDisplay to 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 from myApp_FolderContextMenuDisplay to contextButton_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加载项)上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆