0

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

我有如下代码片段。任何帮助,将不胜感激。

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

3 回答 3

1

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

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

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

于 2008-08-23T14:28:20.307 回答
0

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

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

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

于 2008-09-20T04:36:57.457 回答
0

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

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

尝试将 Style 属性设置为msoButtonCaption

于 2009-03-10T04:49:50.630 回答