使用.NET的Outlook加载项
我们一直在使用VisualStudio2008开发Outlook加载项。但是,在向自定义命令栏添加命令按钮时,我遇到了一个奇怪的行为。当我们在reply、reply all和forward窗口中添加按钮时,就会反映出这种行为。问题是命令按钮的标题不可见,尽管当我们使用VS进行调试时,它正确地显示了标题。但在Outlook(2003)中查看时,该按钮没有标题 我有如下代码片段。任何帮助都将不胜感激使用.NET的Outlook加载项,.net,outlook,add-in,.net,Outlook,Add In,我们一直在使用VisualStudio2008开发Outlook加载项。但是,在向自定义命令栏添加命令按钮时,我遇到了一个奇怪的行为。当我们在reply、reply all和forward窗口中添加按钮时,就会反映出这种行为。问题是命令按钮的标题不可见,尽管当我们使用VS进行调试时,它正确地显示了标题。但在Outlook(2003)中查看时,该按钮没有标题 我有如下代码片段。任何帮助都将不胜感激 private void AddButtonInNewInspector(Microsoft.Off
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来完成此加载项。看见我在很多项目中都使用过它,包括一些商业软件,它非常棒 它为您完成所有Outlook(和office)集成,因此您只需像使用任何工具栏一样使用它,只需关注您需要它做什么的细节。您根本不必担心Outlook的可扩展性。强烈推荐
不管怎么说,我只是想提一提这件事。如果您对在项目中使用第三方组件感到满意,那么肯定会省去一些麻烦。我不知道,但您的代码提出了两个问题:
您没有设置命令栏按钮的样式属性(据我所知) 这导致按钮的MsoButtonStyle为msoButtonAutomation。我看到,如果将样式保留在这个位置,标题将无法显示 尝试将样式属性设置为msoButtonCaption