【问题标题】:VSTO CommandBarButton click modifierVSTO CommandBarButton 点击​​修饰符
【发布时间】:2021-08-27 15:22:47
【问题描述】:

我在 Outlook 中使用 VSTO、CommandBarPopup 和 CommandBarButton 创建了一个工具栏菜单层次结构。我在 CommandBarButton 上设置了一个 Click 处理程序,一切正常,但我希望能够在单击处理程序中执行不同的操作,具体取决于用户是右键单击菜单,还是左键单击或不单击(例如,在自动撰写模板回复时包含或不包含原始消息)。

如何检测用户点击了哪个鼠标按钮,或者用户点击时是否按下了 shift、alt 或 ctrl 键?

【问题讨论】:

    标签: outlook vsto outlook-addin


    【解决方案1】:

    在事件处理程序中,您可以使用Keyboard.GetKeyStates 方法获取指定键的键状态集。

    // Uses the Keyboard.GetKeyStates to determine if a key is down.
    // A bitwise AND operation is used in the comparison. 
    if ((Keyboard.GetKeyStates(Key.LeftShift) & KeyStates.Down) > 0)
    {
        // the left shift is pressed now
    }
    

    CommandBars 在 Office 2010 中已弃用。您需要使用 Fluent UI 在加载项中创建自定义 UI。 VSTO 中创建自定义 UI 的主要方式有两种:

    上下文菜单也是使用 Fluent UI 自定义的。请参阅Extending the User Interface in Outlook 2010 了解更多信息。

    Fluent UI 在以下系列文章中有深入介绍:

    【讨论】:

    • 谢谢;不推荐使用 CommandBars 可能是真的,将来我可能不得不切换到 Ribbon xml(或其他东西),但截至目前,CommandBars 在 Outlook 2019 中仍然可以正常工作,所以我仍然想回答我的问题。
    • CommandBars 出于兼容性目的而保留在那里,控件会自动转换为功能区并显示在“加载项”选项卡上。但我建议直接使用功能区控件。
    • 我已经用命令栏所需的答案更新了帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多