C# winForm 窗体设置了this.FormBorderStyle = FormBorderStyle.None; 后,怎么设置能修改窗体大小
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;
/// <summary>
/// 重写Windows 消息处理函数,用于不带标题的窗口移动
/// </summary>
/// <param name="m"></param>
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);
}
/// <summary>
/// 窗体的MouseMove事件处理函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
SelfMouseMove(sender, e); // 调用 MouseMove函数
}
#endregion