Visual Studio拖动窗体

时间:2017-04-20 09:24:00

标签: c# forms drag

有人可以向我解释这段代码的工作原理

public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;

    [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

private void mainForm_MouseDown(object sender, MouseEventArgs e)
    { //When a mouseButton is pressed down on the form
        if (e.Button == MouseButtons.Left) 
        { // if it is mouseButton1
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }

我知道它可以让我的形式被拖走,但我不明白怎么做。

谢谢!

0 个答案:

没有答案