无边框的界面实现鼠标拖动
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern bool ReleaseCapture();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);
private readonly UInt32 WM_SYSCOMMAND = 0x112;
private readonly UInt32 SC_MOVE = 0xF010;
private readonly UInt32 HTCAPTION = 2;
private void Form1_Load(object sender, EventArgs e)
{
this.MouseDown += MyMouseMove;
foreach (Control c in this.Controls)
{
c.MouseDown += MyMouseMove;
}
}
private void MyMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
参考:http://bbs.csdn.net/topics/390159690