使用.NET的Outlook加载项

问题描述:

我们一直在使用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"); 
      } 
     } 

我不知道你的问题的答案,但我强烈推荐使用Add-In Express做外挂。请参阅http://www.add-in-express.com/add-in-net/。我在很多项目中都使用过这个功能,其中包括一些商业软件,而且它非常棒。

它为您完成所有Outlook(和办公室)集成,因此您只需像任何工具栏一样使用它,并只专注于您所需的特定细节。您永远不必担心Outlook的可扩展性。强烈推荐。

无论如何,只是想提及它作为东西来看。如果您愿意在项目中使用第三方组件,它肯定会节省一些头痛的问题。

我不知道,但你的代码产生了两个问题:

  1. 你为什么声明 “的CommandBarControl myCommandbarButton”,而不是 “CommandBarButton的myCommandbarButton”?

  2. 为什么要将宽度设置为900像素?这是巨大的。我从来不会在Excel中自动调整这个设置,我猜测Outlook的行为是一样的。

您没有设置命令栏按钮的样式属性(从我所知道的)。

这会导致按钮的MsoButtonStyle为msoButtonAutomation。我已经看到如果样式留在这里,标题就不会出现。

尝试将Style属性设置为msoButtonCaption