protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (leftFlag) { Point mouseSet = Control.MousePosition; //设置移动后的位置 mouseSet.Offset(mouseOff.X, mouseOff.Y); Location = mouseSet; return; } if (TitleRect.Contains(e.Location)) { DetectionMousePoint(e.Location); this.Invalidate(TitleRect); return; } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button != MouseButtons.Left) { return; } if (!TitleRect.Contains(e.Location)) { return; } if (DetectionMousePoint(e.Location)) { ManageFormState(); return; } mouseOff = new Point(-e.X, -e.Y); leftFlag = true; }
/// <summary> /// 拖动窗口大小。 /// </summary> /// <param name="m"></param> protected virtual void DragFormSize(ref Message m) { bool isR = false; int param = m.LParam.ToInt32(); Point point = new Point(param & 0xFFFF, param >> 16); point = PointToClient(point); if (this.WindowState != FormWindowState.Maximized) { if (IsResize) { if (point.X <= 3) { if (point.Y <= 3) { m.Result = (IntPtr)WM_NCHITTEST.HTTOPLEFT; isR = true; } else if (point.Y > Height - 3) { m.Result = (IntPtr)WM_NCHITTEST.HTBOTTOMLEFT; isR = true; } else { m.Result = (IntPtr)WM_NCHITTEST.HTLEFT; isR = true; } } else if (point.X >= Width - 3) { if (point.Y <= 3) { m.Result = (IntPtr)WM_NCHITTEST.HTTOPRIGHT; isR = true; } else if (point.Y >= Height - 3) { m.Result = (IntPtr)WM_NCHITTEST.HTBOTTOMRIGHT; isR = true; } else { m.Result = (IntPtr)WM_NCHITTEST.HTRIGHT; isR = true; } } else if (point.Y <= 3) { m.Result = (IntPtr)WM_NCHITTEST.HTTOP; isR = true; } else if (point.Y >= Height - 3) { m.Result = (IntPtr)WM_NCHITTEST.HTBOTTOM; isR = true; } } } if (!isR) { if (TitleRect.Contains(point)) { if (!this.MaximizeBox || CloseRect.Contains(point) || MaxRect.Contains(point) || MiniRect.Contains(point) || SkinRect.Contains(point)) { return; } m.Result = (IntPtr)2; } } }