
[英]Create an Add-in Outlook MSI with Add-in Express from a classic .Net Add-in project
[英]Outlook Add-in using .NET
我们已经在使用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");
}
}
我不知道您问题的答案,但我强烈建议您使用Add-In Express进行加载。 请参阅http://www.add-in-express.com/add-in-net/ 。 我已经在许多项目中使用了此功能,包括一些商业软件,它非常棒。
它为您完成了所有Outlook(和Office)集成,因此您可以像使用任何工具栏一样使用它,并专注于您需要执行的操作的细节。 您根本不必担心Outlook的可扩展性。 强烈推荐。
无论如何,只是想提一下它是值得研究的东西。 如果您愿意在项目中使用第3方组件,则肯定会省去一些麻烦。
我不知道,但是您的代码提出了两个问题:
为什么要声明“ CommandBarControl myCommandbarButton”而不是“ CommandBarButton myCommandbarButton”?
为什么将宽度设置为900像素? 好大 由于它会自动调整大小,因此我从不理会Excel中的此设置,并且我猜测Outlook的行为将相同。
您没有设置命令栏按钮的style属性(据我所知)。
这将导致按钮的MsoButtonStyle为msoButtonAutomation 。 我已经看到,如果样式保留在此处,标题将不会出现。
尝试将Style属性设置为msoButtonCaption 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.