右键双击和上下文菜单

发布于 2024-10-08 03:25:02 字数 1537 浏览 0 评论 0原文

相关问题(详细信息)

隧道事件和 ContextMenu

我有一个与 ContextMenu 关联的 WPF 画布..

这很酷。现在我必须对 Right DoubleClick 执行一些操作...

事实上,我从未收到 Right mouse ClickCount == 2...

该怎么办?
我需要在简单(右键)单击时显示 ContextMenu,并执行 Action2 OnRightDoubleClick..

protected override void OnPreviewMouseRightButtonUp(MouseButtonEventArgs e)
{
    if (e.ClickCount == 1)
    {
        #region SINGLE CLICK
        stillSingleClick = true;
        Thread thread = new Thread(
            new System.Threading.ThreadStart(
                delegate()
                {
                    Thread.Sleep(System.Windows.Forms.SystemInformation.DoubleClickTime);
                    this.Dispatcher.Invoke(
                        System.Windows.Threading.DispatcherPriority.Background,
                        new Action(
                            delegate()
                            {
                                if (stillSingleClick)
                                {
                                    base.OnPreviewMouseRightButtonUp(e);
                                }
                                stillSingleClick = false;
                            }
                    ));
                }
        ));
        thread.Start();
        #endregion SINGLE CLICK
    }
    else if (e.ClickCount == 2)
    {
        stillSingleClick = false;
        base.OnPreviewMouseRightButtonUp(e);
    }
}

Related Question (Details)

Tunneling events and ContextMenu

I have a WPF canvas to which I associated a ContextMenu..

This is cool. Now I have to implement some action on Right DoubleClick...

In fact, I never receive on Right mouse ClickCount == 2...

What to do?
I need to display ContextMenu on simple (right) click, and perform Action2 OnRightDoubleClick..

protected override void OnPreviewMouseRightButtonUp(MouseButtonEventArgs e)
{
    if (e.ClickCount == 1)
    {
        #region SINGLE CLICK
        stillSingleClick = true;
        Thread thread = new Thread(
            new System.Threading.ThreadStart(
                delegate()
                {
                    Thread.Sleep(System.Windows.Forms.SystemInformation.DoubleClickTime);
                    this.Dispatcher.Invoke(
                        System.Windows.Threading.DispatcherPriority.Background,
                        new Action(
                            delegate()
                            {
                                if (stillSingleClick)
                                {
                                    base.OnPreviewMouseRightButtonUp(e);
                                }
                                stillSingleClick = false;
                            }
                    ));
                }
        ));
        thread.Start();
        #endregion SINGLE CLICK
    }
    else if (e.ClickCount == 2)
    {
        stillSingleClick = false;
        base.OnPreviewMouseRightButtonUp(e);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

獨角戲 2024-10-15 03:25:02

MouseButtonEventArgs.ClickCount 将始终为 1,因为您处理的是向上事件而不是向下事件。 PreviewUp 和 Up 都始终为 1。单击行为通常定义为相应按钮的按下事件。

MouseButtonEventArgs.ClickCount will always be 1 since you are handling an up event not a down event. Both the PreviewUp and Up will always be 1. The click behavior is usually defined as the down event of the respective button.

戏蝶舞 2024-10-15 03:25:02

MouseDoubleClickEvent 中执行此操作

if (e.ChangedButton == MouseButton.Right)
{
     //do something with Mouse Right Double Click
}

Do this in MouseDoubleClickEvent

if (e.ChangedButton == MouseButton.Right)
{
     //do something with Mouse Right Double Click
}
灵芸 2024-10-15 03:25:02

在 MSDN 上查看示例:

private void OnMouseDownClickCount(object sender, MouseButtonEventArgs e)
{
    //Handle only right clicks
    if (e.RightButton != MouseButtonState.Pressed) return;

    // Checks the number of clicks.
    if (e.ClickCount == 1)
    {
        // Single Click occurred.
        lblClickCount.Content = "Single Click";
    }
    if (e.ClickCount == 2)
    {
        // Double Click occurred.
        lblClickCount.Content = "Double Click";
    }
    if (e.ClickCount >= 3)
    {
        // Triple Click occurred.
        lblClickCount.Content = "Triple Click";
    }
}

Check out this example at MSDN:

private void OnMouseDownClickCount(object sender, MouseButtonEventArgs e)
{
    //Handle only right clicks
    if (e.RightButton != MouseButtonState.Pressed) return;

    // Checks the number of clicks.
    if (e.ClickCount == 1)
    {
        // Single Click occurred.
        lblClickCount.Content = "Single Click";
    }
    if (e.ClickCount == 2)
    {
        // Double Click occurred.
        lblClickCount.Content = "Double Click";
    }
    if (e.ClickCount >= 3)
    {
        // Triple Click occurred.
        lblClickCount.Content = "Triple Click";
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文