【问题标题】:Outlook Add-in using .NET使用 .NET 的 Outlook 加载项
【发布时间】:2008-08-23 09:57:28
【问题描述】:

我们一直在使用 Visual Studio 2008 开发 Outlook 插件。但是,在将命令按钮添加到自定义命令栏时,我遇到了一个奇怪的行为。当我们在回复、全部回复和转发窗口中添加按钮时,就会体现这种行为。问题是命令按钮的标题不可见,尽管当我们使用 VS 进行调试时,它会正确显示标题。但在 Outlook(2003) 中查看时,该按钮没有字幕。

我有如下代码 sn-p。任何帮助将不胜感激。

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");
            }
        }

【问题讨论】:

    标签: .net outlook add-in


    【解决方案1】:

    我不知道您的问题的答案,但我强烈建议您使用 Add-In Express 来执行插件。见http://www.add-in-express.com/add-in-net/。我在很多项目中都使用过它,包括一些商业软件,它非常棒。

    它为您完成所有 Outlook(和 Office)集成,因此您只需像使用任何工具栏一样使用它,只需专注于您需要它执行的具体操作。您根本不必担心 Outlook 的可扩展性。强烈推荐。

    无论如何,只是想提一下它作为值得关注的东西。如果您对在项目中使用 3rd 方组件感到满意,它肯定会省去一些麻烦。

    【讨论】:

      【解决方案2】:

      我不知道,但您的代码提出了两个问题:

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

      2. 为什么将宽度设置为 900 像素?那是巨大的。我从来不用 Excel 中的这个设置,因为它会自动调整大小,而且我猜 Outlook 的行为也会一样。

      【讨论】:

        【解决方案3】:

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

        这会导致按钮的 MsoButtonStyle 为 msoButtonAutomation。如果样式保留在此处,我已经看到标题无法出现。

        尝试将 Style 属性设置为 msoButtonCaption

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-02-12
          • 2019-06-29
          • 1970-01-01
          • 1970-01-01
          • 2012-08-24
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多