C# 无边框窗体移动

你新建个窗体。不用修改一行代码。双击窗体或查看代码。在Form1类中粘贴如下代码就能实现了。

[System.Runtime.InteropServices.DllImport("user32.dll")]   
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wparam, int lparam);   
protected override void OnMouseDown(MouseEventArgs e)   
{   
    base.OnMouseDown(e);   
    if (e.Button == MouseButtons.Left)//按下的是鼠标左键   
    {   
        Capture = false;//释放鼠标,使能够手动操作   
        SendMessage(this.Handle, 0x00A1, 2, 0);//拖动窗体   
    }   
} 

千人.NET交流群:18362376,因为有你,代码变得更简单,加群请输入cnblogs
原文地址:https://www.cnblogs.com/kingkoo/p/1875407.html