2015-09-16 69 views
0

我開發一個插件前景VSTO,我試圖把一個單獨的表格區域顯示爲在打開檢查當前表單頁面,但拋出異常。這裏是代碼提前C#的Outlook外接setCurrentFormPage拋出異常

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
    { 
     this.Application.Inspectors.NewInspector += InspectorsOnNewInspector; 
     this.Application.Explorers.NewExplorer += Explorers_NewExplorer; 
    } 

    private void Explorers_NewExplorer(Outlook.Explorer explorer) 
    { 

    } 

    private void InspectorsOnNewInspector(Outlook.Inspector inspector) 
    { 
     MessageBox.Show("ola"); 
     // exception ocurrs in this line 
     inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion"); 

    } 

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e) 
    { 
    } 

感謝。

回答

0

我設法把它與下面的代碼

private void InspectorsOnNewInspector(Outlook.Inspector inspector) 
    { 

     MessageBox.Show("ola"); 

     if (!(inspector.CurrentItem is Outlook.TaskItem)) return; 

     var taskItem = (Outlook.TaskItem) inspector.CurrentItem; 

     taskItem.Open += (ref bool cancel) => 
     { 
      try 
      { 
       inspector.SetCurrentFormPage("OutlookAddIn.RequestFormRegion"); 

      } 
      catch (Exception ex) 
      { 
       System.Windows.Forms.MessageBox.Show(ex.Message); 
      } 
     }; 
    } 
+0

你可能想使taskItem全局/類變量工作 - 否則,如果avriable得到NewInspector間垃圾收集Open事件將不會觸發和Open事件。 –