[英]C# (outlook add-in) context menu on folders
在我的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
中的contextButton_Click
MAPIFolder Folder
發送到contextButton_Click
?
(如果這可以通過另一種方式完成,我也可以提出建議)
最簡單的方法就是使用閉包,例如:
// 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現在可能具有“延長的生命周期”,因為閉包可以比以前更長時間保持活動(但是在不需要時手動釋放RCW 非常重要 。)
快樂的編碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.