如何捕捉鼠标在HTCAPTION上移动

本文关键字:移动 HTCAPTION 何捕捉 鼠标 | 更新日期: 2023-09-27 17:58:19

我有一个表单,它将所有背景设置为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。鼠标移动事件。

    private void FormMain_MouseMove(Object sender, MouseEventArgs e)
    {
        Point p = e.Location;
        Console.WriteLine(p);
    }

如何观看MouseMove活动?

如何捕捉鼠标在HTCAPTION上移动

在VB.net中,它是

MyBase.WndProc(m)

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

this.WndProc(m)

把它放在if语句之前。