【问题标题】:How to disable default PowerPoint event functionality of double click and right click?如何禁用双击和右键单击的默认 PowerPoint 事件功能?
【发布时间】:2014-05-06 05:33:07
【问题描述】:

在我使用 VSTO 的 PowerPoint 插件中,我正在实现一个 Application-level Mouse Hook 来捕获鼠标事件,例如双击、右键单击、鼠标悬停等,方法是使用从 Codeplex 下载的 MouseKeyboardActivityMonitor.dll。我这样做的原因是因为 PowerPoint 没有要收听的鼠标相关事件,并且它提供的事件不会在 PowerPoint 的编辑模式下触发。

在我的插件中,当用户单击图表时,会出现一个菜单,允许用户在图表上执行各种功能。一切正常。我已经捕获了鼠标事件并显示了自定义菜单,但是在执行某些操作后关闭菜单时会出现问题,PowerPoint 的默认菜单会出现在屏幕上。

示例:当用户双击图表时,我会像这样显示我的表单菜单。

//Listening to the MouseDoubleClick event
MyMouseHookListener.MouseDoubleClick += MyMouseHookListener_MouseDoubleClick;

//MouseDoubleClickEvent
void MyMouseHookListener_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
    FormMenu.ShowDialog(); //Displaying menu
}

这很好用,但是当用户关闭表单时,会出现 PowerPoint 图表的默认双击菜单。其他鼠标事件的问题也是如此。

如何禁用 PowerPoint 的事件菜单?

更新:

有一个名为Cancelbool 属性由PowerPoint 的WindowBeforeDoubleClickWindowBeforeRightClick 事件提供。如果设置为true,则会取消 PowerPoint 在触发事件时执行的默认操作。如何在我的 MouseHook 事件中访问此属性?

【问题讨论】:

    标签: c# events mouseevent vsto powerpoint


    【解决方案1】:

    MouseKeyboardActivityMonitor 引发了几个可用事件。对于鼠标按下事件,您可以选择收听MouseDownMouseDownExt。后者在MouseEventExtArgs 参数中为您提供了一些额外的选项,例如Handled 属性。如果将此设置为 true,则事件不会进一步传播。

    对于MouseDoubleClick 事件,没有可用的扩展事件。因此,我建议您通过使用MouseDownExt 侦听器并计算已发生的点击次数来自己实现双击侦听器。

    public void Initialize() {
        // Initialize your listener and set up event listeners
        MyMouseHookListener = new MouseHookListener(new AppHooker()) {Enabled = true};
        MyMouseHookListener.MouseDownExt += MyMouseHookListenerOnMouseDownExt;
    
        // UNDONE Delete when testing is done; included to show that the listener is never called
        MyMouseHookListener.MouseDoubleClick += MyMouseHookListenerOnMouseDoubleClick;
    }
    
    private static void MyMouseHookListenerOnMouseDoubleClick(object sender, MouseEventArgs mouseEventArgs)
    {
        // NOTE: This listener should never be called
        Debug.Print("Mouse double-click!");
    }
    
    private static void MyMouseHookListenerOnMouseDownExt(object sender, MouseEventExtArgs mouseEventExtArgs)
    {
        Debug.Print("Mouse down. Number of clicks: {0}", mouseEventExtArgs.Clicks);
    
        if (mouseEventExtArgs.Clicks == 2)
        {
            // TODO Insert your double-click code here
            mouseEventExtArgs.Handled = true;
        }
    }
    

    为了详尽无遗,您或许还应该测试被单击的是左按钮还是右按钮,您可以通过检查MouseEventExtArgs.Button 属性来测试。右键双击现在将被视为双击,但是据我所知,这与原始的MouseDoubleClick 事件相似。

    【讨论】:

      猜你喜欢
      • 2021-06-26
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多