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