private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
public const int HWND_BROADCAST = 0xFFFF;
public const int WM_FONTCHANGE = 0x1D;
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public static int WM_SYSCOMMAND = 0x0112;
public static int SC_MOVE = 0xF010;
///
/// 重写Windows 消息处理函数,用于不带标题的窗口移动
///
///
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if ((int)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
return;
}
base.WndProc(ref m);
}
#region == 通过API来实现拖动鼠标改变窗口大小 ==
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style |= 0xC0000 + 0x20000;
return cp;
}
}
private void SelfMouseMove(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
///
/// 窗体的MouseMove事件处理函数
///
///
///
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
SelfMouseMove(sender, e); // 调用 MouseMove函数
}
#endregion