0

我有一个表单,将其所有背景设置为 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 事件?

4

1 回答 1

0

在 VB.net 中是

MyBase.WndProc(m)

所以,如果我错了,请纠正我,但我猜是在 C# 中。

this.WndProc(m)

? 把它放在你的 if 语句之前。

于 2013-03-20T16:46:21.877 回答