文件夹上的 C#(Outlook 加载项)上下文菜单
在我的 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
}
我的问题是如何从 myApp_FolderContextMenuDisplay 发送该
到 MAPIFolder 文件夹
contextButton_Click
?
(如果这可以通过其他方式完成,我也欢迎建议)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法就是使用闭包,例如:
如果需要,请确保清理事件。需要注意的一件事是,文件夹的 RCW 现在可能具有“延长的生命周期”,因为关闭可能会使其存活时间比以前更长(但对于 OOM,手动释放非常重要不需要时使用 RCW。)
快乐编码。
Easiest way is just to use a closure, for example:
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.