public partial class frmMove : Form { public frmMove() { InitializeComponent(); } internal static int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息 internal static IntPtr HTCLIENT = (IntPtr)0x1;//工作区 internal static IntPtr HTCAPTION = (IntPtr)0x2; //标题栏 protected override void WndProc(ref Message m) { if (m.Msg == WM_NCHITTEST) { base.WndProc(ref m); if (m.Result == HTCLIENT) { m.HWnd = this.Handle; System.Drawing.Rectangle rect = this.RectangleToScreen(this.ClientRectangle); Point C_Pos = Cursor.Position; m.Result = HTCAPTION;//模拟标题栏,移动或双击可以最大或最小化窗体 } } else { base.WndProc(ref m); } } }
关于窗体的拖动
最新推荐文章于 2024-09-11 15:57:39 发布