How to detect size grip double-click event?

六眼飞鱼酱① 提交于 2019-12-24 13:26:35

问题


I'm looking for a way to detect double-click on a window size grip, but there doesn't seem to be even a single click event for the size grip, or any event related to it at all. Guessing the size of grip area and whether the user is truly clicking the desired area is an unnecessarily difficult job. But maybe there are some other ways to detect if the cursor is on a form's size grip, besides default winform properties?

Is there an easy way to know when user is double-clicking a form's size grip?


回答1:


You need to:

  1. Set up a way to receive a mouse double-click event on the non-client area of the form.
  2. Define a hitbox within which you care to react to that event.
  3. React to the event when it's in your hitbox.

Override the WndProc form method to achieve this:

    protected override void WndProc(ref Message m)
    {
        const Int32 WM_NCLBUTTONDBLCLK = 0xA3;
        if (m.Msg == WM_NCLBUTTONDBLCLK)
        {
            //This is a 16x16 region...define the bounds you want...
            Rectangle hitbox = new Rectangle(this.Right - 16, this.Bottom - 16, 16, 16);
            Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
            if (hitbox.Contains(pos))
                MessageBox.Show("got it");  //react however you like
        }
        base.WndProc(ref m);
    }


来源:https://stackoverflow.com/questions/21769565/how-to-detect-size-grip-double-click-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!