在我的VSTO outlook插件中,我正在尝试放置一个按钮,当我右键单击文件夹时会显示该按钮.在我的启动功能中我有这个:
Outlook.Application myApp = new Outlook.ApplicationClass();
myApp.FolderContextMenuDisplay += new ApplicationEvents_11_FolderContextMenuDisplayEventHandler(myApp_FolderContextMenuDisplay);
Run Code Online (Sandbox Code Playgroud)
然后我有那个处理程序...
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);
}
Run Code Online (Sandbox Code Playgroud)
最后点击的处理程序....
void contextButton_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
//stuff here
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我怎么发送MAPIFolder Folder从myApp_FolderContextMenuDisplay到contextButton_Click?
(如果这可以通过另一种方式完成,我也可以提出建议)
小智 3
最简单的方法就是使用闭包,例如:
// 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);
};
Run Code Online (Sandbox Code Playgroud)
如果需要,请确保清理事件。需要注意的一件事是,文件夹的 RCW 现在可能具有“延长的生命周期”,因为关闭可能会使其存活时间比以前更长(但对于 OOM,在不需要时手动释放 RCW非常重要。)
快乐编码。
| 归档时间: |
|
| 查看次数: |
2626 次 |
| 最近记录: |