什么时候举行DoubleClick活动而不是双击鼠标?

时间:2012-02-22 10:23:32

标签: .net winforms

The documentation for the MouseDoubleClick event

  

重要

     

DoubleClick事件是控件的逻辑上更高级别的事件。它们可能由其他用户操作引发,例如快捷键组合。

但是,在DoubleClick未提出MouseDoubleClick的情况下,我无法找到引发{{1}}事件的控件,the documentation for DoubleClick event没有什么都提。这是什么时候使用的?

1 个答案:

答案 0 :(得分:0)

有些情况下你需要鼠标属性(位置,点击..),所以你使用mousedoubleclicks事件,在其他情况下你不需要它们,所以系统可以节省一些字节并提高性能。

例如下面的应用程序几乎是纯粹的GDI,所以当我点击一些地方时,我的鼠标属性非常重要......

enter image description here

<强>更新

你是对的:

1 :没有引发双击并且moused双击没有的情况,反之亦然,因为我反编译.Net 3.5中的控件类,并发现牵引事件的唯一地方是在同一个地方onmouseup有一些条件:

private void WmMouseUp(ref Message m, MouseButtons button, int clicks)
{
    try
    {
        int x = NativeMethods.Util.SignedLOWORD(m.LParam);
        int y = NativeMethods.Util.SignedHIWORD(m.LParam);
        Point p = new Point(x, y);
        p = this.PointToScreen(p);
        if (!this.GetStyle(ControlStyles.UserMouse))
        {
            this.DefWndProc(ref m);
        }
        else if (button == MouseButtons.Right)
        {
            this.SendMessage(0x7b, this.Handle, NativeMethods.Util.MAKELPARAM(p.X, p.Y));
        }
        bool flag = false;
        if ((((this.controlStyle & ControlStyles.StandardClick) == ControlStyles.StandardClick) && this.GetState(0x8000000)) && (!this.IsDisposed && (UnsafeNativeMethods.WindowFromPoint(p.X, p.Y) == this.Handle)))
        {
            flag = true;
        }
        if (flag && !this.ValidationCancelled)
        {
            if (!this.GetState(0x4000000))
            {
                this.OnClick(new MouseEventArgs(button, clicks, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
                this.OnMouseClick(new MouseEventArgs(button, clicks, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
            }
            else
            {
                this.OnDoubleClick(new MouseEventArgs(button, 2, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
                this.OnMouseDoubleClick(new MouseEventArgs(button, 2, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
            }
        }
        this.OnMouseUp(new MouseEventArgs(button, clicks, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0));
    }
    finally
    {
        this.SetState(0x4000000, false);
        this.SetState(0x8000000, false);
        this.SetState(0x10000000, false);
        this.CaptureInternal = false;
    }
}

2 :如果不存在处理程序,则不会调用处理程序调用:

[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnMouseDoubleClick(MouseEventArgs e)
{
    MouseEventHandler handler = (MouseEventHandler) base.Events[EventMouseDoubleClick];
    if (handler != null)
    {
        handler(this, e);
    }
}