2008-08-23 44 views
0

我們一直在使用Visual Studio 2008開發Outlook加載項。但是,在向自定義命令欄添加命令按鈕時,我遇到了奇怪的行爲。當我們在回覆中添加按鈕,回覆所有和轉發窗口時,會反映此行爲。問題是命令按鈕的標題不可見,儘管當我們使用VS進行調試時,它正確顯示了標題。但在Outlook(2003)中查看該按鈕時無字幕。使用.NET的Outlook加載項

我有如下的代碼片段。任何幫助,將不勝感激。

private void AddButtonInNewInspector(Microsoft.Office.Interop.Outlook.Inspector inspector) 
     { 
      try 
      { 
       if (inspector.CurrentItem is Microsoft.Office.Interop.Outlook.MailItem) 
       { 


        try 
        {      
         foreach (CommandBar c in inspector.CommandBars) 
         { 
          if (c.Name == "custom") 
          { 
           c.Delete(); 
          } 
         } 
        } 
        catch 
        { 
        } 
        finally 
        { 
         //Add Custom Command bar and command button. 
         CommandBar myCommandBar = inspector.CommandBars.Add("custom", MsoBarPosition.msoBarTop, false, true); 
         myCommandBar.Visible = true; 

         CommandBarControl myCommandbarButton = myCommandBar.Controls.Add(MsoControlType.msoControlButton, 1, "Add", System.Reflection.Missing.Value, true);       
         myCommandbarButton.Caption = "Add Email"; 
         myCommandbarButton.Width = 900; 
         myCommandbarButton.Visible = true; 
         myCommandbarButton.DescriptionText = "This is Add Email Button"; 

         CommandBarButton btnclickhandler = (CommandBarButton)myCommandbarButton; 
         btnclickhandler.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.OnAddEmailButtonClick); 
        } 


       } 
      } 
      catch (System.Exception ex) 
      { 
       MessageBox.Show(ex.Message.ToString(), "AddButtInNewInspector"); 
      } 
     } 

回答

1

我不知道你的問題的答案,但我強烈推薦使用Add-In Express做外掛。請參閱http://www.add-in-express.com/add-in-net/。我在很多項目中都使用過這個功能,其中包括一些商業軟件,而且它非常棒。

它爲您完成所有Outlook(和辦公室)集成,因此您只需像任何工具欄一樣使用它,並只專注於您所需的特定細節。您永遠不必擔心Outlook的可擴展性。強烈推薦。

無論如何,只是想提及它作爲東西來看。如果您願意在項目中使用第三方組件,它肯定會節省一些頭痛的問題。

0

我不知道,但你的代碼產生了兩個問題:

  1. 你爲什麼聲明 「的CommandBarControl myCommandbarButton」,而不是 「CommandBarButton的myCommandbarButton」?

  2. 爲什麼要將寬度設置爲900像素?這是巨大的。我從來不會在Excel中自動調整這個設置,我猜測Outlook的行爲是一樣的。

0

您沒有設置命令欄按鈕的樣式屬性(從我所知道的)。

這會導致按鈕的MsoButtonStyle爲msoButtonAutomation。我已經看到如果樣式留在這裏,標題就不會出現。

嘗試將Style屬性設置爲msoButtonCaption