2
我想寫一個插件,通知時約會保存並做一些數據。爲此,我需要檢查活動檢查員關閉時是否保存該項目。展望地址條目保存
我的問題是這樣的:當試圖將WriteEvent
-listener綁定到FormRegionShowing
-方法中的當前項目時,我需要ActiveInspector
來獲取當前項目。但是,在獲取ActiveInspector
時,可能是null
,因爲在活動檢查器實際處於活動狀態之前調用該方法。
然而,試圖在FormRegionClosed
-方法中綁定它時,write事件從不觸發。那麼,我怎麼知道AppointmentItem
實際上是由用戶保存的呢?
編輯:我設法在FormRegionShowing
- 方法寫綁定事件,但它仍然不會火:
private void ADDIN_NAME_FormRegionShowing(object sender, System.EventArgs e){
Outlook.AppointmentItem currentItem = (Outlook.AppointmentItem)this.OutlookItem;
currentItem.Write += new Outlook.ItemEvents_10_WriteEventHandler(currentItem_Write);
currentItem.AfterWrite += new Outlook.ItemEvents_10_AfterWriteEventHandler(currentItem_AfterWrite);
MessageBox.Show("added handlers");
}
void currentItem_AfterWrite(){
MessageBox.Show("item has been saved");
}
void currentItem_Write(ref bool Cancel){
MessageBox.Show("item being saved");
}
太棒了,非常感謝! – arik
但是使用這段代碼,其效果是每次打開和編輯事件時,Write和AfterWrite事件的數量都會加1。測試中的MessageBox顯示N次,N是項目打開和編輯的次數! :( –
@CesarVega - 聽起來像'currentItem'在事件視圖之間持續存在。您需要在Form區域關閉後斷開事件。請查看['FormRegionClosed'](http://msdn.microsoft.com/ en-us/library/microsoft.office.tools.outlook.formregioncontrol.formregionclosed.aspx)並斷開「Write」/'AfterWrite'事件(*通過操作符重載 - = *) – SliverNinja