当把窗体的FormBorderStyle属性设为None后会导致边框没了,结果窗体无法用鼠标拖动、最大、最下化和关闭……
下面解决窗体可拖动问题:
1.首先导入命名空间:
using System.Runtime.InteropServices;
2.然后如下代码:
[DllImport("user32.dll")] public 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(Handle, 0x00A1, 2, 0);//拖动窗体 } }