protected override void OnMouseClick(MouseEventArgs e) { if (CloseRect == Rectangle.Empty) { CloseRect = new Rectangle(Width - 70, 0, 50, 25); } if (CloseRect.Contains(e.Location)) { this.Close(); } base.OnMouseClick(e); }
protected override void OnMouseDown(MouseEventArgs e) { if (CloseRect == Rectangle.Empty) { CloseRect = new Rectangle(Width - 60, 0, 50, 25); } if (!CloseRect.Contains(e.Location)) { isMouseDown = true; oldMousePoint = this.PointToScreen(e.Location); oldWindowPoint = this.Location; this.Cursor = Cursors.SizeAll; } base.OnMouseDown(e); }
private bool CloseContains(Point point) { return(CloseRect.Contains(point) || (CloseRect.Contains(new Point(CloseRect.X, point.Y)) && point.Y < CloseRect.Height && point.X > CloseRect.X)); }
/// <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; } } }