如何放置Outlook 2007/2010 VSTO上下文菜单按钮? [英] How to position Outlook 2007/2010 VSTO Context Menu Button?

查看:134
本文介绍了如何放置Outlook 2007/2010 VSTO上下文菜单按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Outlook 2007/2010加载项,已在其中将上下文菜单按钮成功添加到资源管理器.该按钮本身可以正确显示并且可以正常工作,但是我无法将其放置在上下文菜单的内置控件上方,它始终被添加到底部.我已经使用VSTO 3.0为Outlook 2003加载项创建了相同的按钮,并且相同的代码创建了一个按钮,该按钮位于打开"按钮上方的上下文菜单顶部.

I have an Outlook 2007/2010 add-in where I have successfully added a context-menu button to the explorer. The button itself is displayed correctly and working fine however I am unable to position it above the built-in controls on the context-menu, it is always added to the bottom. I have created the same button using VSTO 3.0 for an Outlook 2003 add-in and the same code creates a button that is at the top of the context menu above the 'Open' button.

我的代码在

 void Application_ItemContextMenuDisplay(CommandBar CommandBar, Selection Selection)
    {
        if (Selection.Count != 1) return;

        CommandBarControl rootButton = CommandBar.Controls.Add(MsoControlType.msoControlButton, Type.Missing, "Create Heat Call", 1, Type.Missing);

        CommandBarButton button = (CommandBarButton)rootButton;

        button.BeginGroup = true;
        button.Tag = "CreateHeatCall";
        button.Caption = "Create Heat Call";
        button.Style = MsoButtonStyle.msoButtonIconAndCaption;
        button.Visible = true;

        button.Picture = GetImage();
        button.Mask = GetImageMask();

        selection = Selection;

        ((CommandBarButton)rootButton).Click += new _CommandBarButtonEvents_ClickEventHandler(ThisAddIn_Click);

    }

我尝试使用CommandBar.Controls.Add()方法的'Before'参数无效.我怀疑问题在于在将其他内置控件添加到上下文菜单之前,已引发ItemContextMenuDisplay事件,而在由Explorer.CommandBars引发的方法中创建了Outlook 2003外接按钮. VSTO 4.0资源管理器对象中不存在的OnUpdate事件.

I have tried playing around with the 'Before' parameter of the CommandBar.Controls.Add() method to no avail. I am suspecting the problem is that the ItemContextMenuDisplay event is being fired before the other built-in controls are added to the context menu, whereas the Outlook 2003 add-in button is being created in a method that is fired by the Explorer.CommandBars.OnUpdate event which doesn't exist in the VSTO 4.0 Explorer object.

是否可以在VSTO 4.0 for Outlook 07/10中添加不在上下文菜单底部的按钮?

Is it possible to add a button that isn't on the bottom of the context menu in VSTO 4.0 for Outlook 07/10?

推荐答案

在Outlook 2003和2007中,上下文菜单基于CommandBar,并使用上面提供的代码创建.在Outlook 2010中,上下文菜单现在基于功能区,并且通常使用XML进行声明.

In Outlook 2003 and 2007, context menus were CommandBar-based, and created using code like the one you provided above. In Outlook 2010, context menus are now Ribbon-based, and typically declared using XML.

在Office 2010中自定义上下文菜单:

在Microsoft Office 2010之前,在Microsoft Office Fluent Ribbon用户界面(UI)中自定义上下文(右键单击)菜单的唯一方法是使用CommandBars解决方案.在Office 2010中,您可以自定义内置上下文菜单,就像功能区UI的其他组件一样.这种基于XML的上下文菜单可扩展性模型基于熟悉的Ribbon功能区可扩展性模型.这意味着您可以使用与当前用于自定义功能区UI相同的XML标记和回调.此外,通过功能区UI扩展性启用上下文菜单自定义功能不会破坏"先前编写的命令栏解决方案.

Prior to Microsoft Office 2010, the only way to customize context (right-click) menus in the Microsoft Office Fluent Ribbon user interface (UI) was by using CommandBars solutions. In Office 2010, you can customize built-in context menus just as you can the other components of the Ribbon UI. This XML-based context menu extensibility model is based on the familiar Ribbon extensibility model. This means that you can use the same XML markup and callbacks that you currently use to customize the Ribbon UI. Additionally, enabling context menu customizations through Ribbon UI extensibility does not "break" previously written command bar solutions.

Outlook 2010支持基于CommandBar的控件的向后兼容性,但有一些警告;无法定位控件可能是其中之一.

Outlook 2010 supports backwards compatibility for CommandBar-based controls, but with some caveats; the inability to position the controls is probably one of them.

我的建议是让您的加载项检测正在运行的Outlook版本是2003/2007还是2010,如果是后者,则创建基于Ribbon的控件而不是基于CommandBar的控件.您将需要研究如何相应地修改代码;例如,可以通过在<button>元素中声明insertBeforeMso属性来执行定位.

My suggestion would be to have your add-in detect whether the running Outlook version is 2003/2007 or 2010 and, in case of the latter, create Ribbon-based controls instead of the CommandBar-based ones. You will need to investigate how to adapt your code accordingly; for example, positioning may be performing by declaring insertBeforeMso attributes in the <button> element.

P.S.我鼓励您考虑切换到商业第三方产品添加-in Express for Microsoft Office和.NET ,用于扩展Office应用程序的UI;它大大简化了VSTO上的过程.您仍然需要创建单独的ADXContextMenu(基于CommandBar)和AdxRibbonContextMenu(基于丝带),但是该过程几乎可以完全使用直观的视觉设计器来完成.

P.S. I would encourage you to consider switching to the commercial third-party product Add-in Express for Microsoft Office and .NET for extending the UI of Office applications; it simplifies the process drastically over VSTO. You would still need to create a separate ADXContextMenu (CommandBar-based) and AdxRibbonContextMenu (Ribbon-based), but the process may be done almost entirely using intuitive visual designers.

这篇关于如何放置Outlook 2007/2010 VSTO上下文菜单按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆