我有一个表单,将其所有背景设置为 HTCAPTION 作为下面的源代码。
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch(m.Msg)
{
case Global.WM_NCHITTEST:
Point mouseCursor = PointToClient(Cursor.Position);
if (mouseCursor.X < borderSize && mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOPLEFT;
else if (mouseCursor.X < borderSize && mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOMLEFT;
else if (mouseCursor.X < borderSize)
m.Result = (IntPtr)Global.HTLEFT;
else if (mouseCursor.X > Width - borderSize && mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOPRIGHT;
else if (mouseCursor.X > Width - borderSize && mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOMRIGHT;
else if (mouseCursor.X > Width - borderSize)
m.Result = (IntPtr)Global.HTRIGHT;
else if (mouseCursor.Y < borderSize)
m.Result = (IntPtr)Global.HTTOP;
else if (mouseCursor.Y > Height - borderSize)
m.Result = (IntPtr)Global.HTBOTTOM;
else
m.Result = (IntPtr)Global.HTCAPTION;
break;
}
}
问题是当设置 HTCAPTION 时,我无法触发 From.MouseMove 事件。
private void FormMain_MouseMove(Object sender, MouseEventArgs e)
{
Point p = e.Location;
Console.WriteLine(p);
}
如何捕捉 MouseMove 事件?