0
我有一個表單將其所有背景設置爲以下源代碼的HTCAPTION。如何在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事件?