无边窗体 鼠标进入窗体边界鼠标状态改变 进行调整窗体大小
来源:互联网 发布:unity3d制作字幕开场 编辑:程序博客网 时间:2024/06/06 04:21
/// <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; } }