问题
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:
- Set up a way to receive a mouse double-click event on the non-client area of the form.
- Define a hitbox within which you care to react to that event.
- 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