/// <summary>
/// 重写改变窗体大小
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
const int WM_NCHITTEST = 0x0084;
int HTCLIENT = 1;
int HTLEFT = 10;
int HTRIGHT = 11;
int HTTOP = 12;
int HTTOPLEFT = 13;
int HTTOPRIGHT = 14;
int HTBOTTOM = 15;
int HTBOTTOMLEFT = 16;
int HTBOTTOMRIGHT = 17;
int offset = 3;
switch (m.Msg)
{
case WM_NCHITTEST:
int px = Form.MousePosition.X - this.Left;
int py = Form.MousePosition.Y - this.Top;
int temp;
if (px >= this.Width - offset)
{
if (py <= offset) temp = HTTOPRIGHT;
else if (py >= this.Height - offset) temp = HTBOTTOMRIGHT;
else temp = HTRIGHT;
}
else if (px <= offset)
{
if (py <= offset) temp = HTTOPLEFT;
else if (py >= this.Height - offset) temp = HTBOTTOMLEFT;
else temp = HTLEFT;
}
else
{
if (py <= offset) temp = HTTOP;
else if (py >= this.Height - offset) temp = HTBOTTOM;
else temp = HTCLIENT;
}
m.Result = (IntPtr)temp;
break;
default:
base.WndProc(ref m);
break;
}
}