public virtual bool OnMouseClickEx(MouseEventArgsEx e) { if (this.MouseClickEx != null) { this.MouseClickEx(this, e); } return(false); }
private void Form360_MouseMoveEx(object sender, MouseEventArgsEx e) { if (this.isResizing) { MouseResize(e); } else { ShowResizeMouseCursor(e); } }
private void Form360_MouseDownEx(object sender, MouseEventArgsEx e) { if (!this.isMouseInResizeArea) { return; } this.isResizing = true; this.resizeOriginWidth = this.Width; this.resizeOriginHeight = this.Height; this.resizeMouseOriginX = e.ScreenX; this.resizeMouseOriginY = e.ScreenY; this.resizeOriginTop = this.Location.Y; this.resizeOriginLeft = this.Location.X; }
private bool RaiseMouseEvent(ref Message m, int x, int y, Control c) { FormEx form = c as FormEx; ControlEx ctrl = c as ControlEx; if (form == null && ctrl == null) { return(false); } MouseEventArgsEx e; bool r = false; switch (m.Msg) { case Win32.WM_MOUSEMOVE: { e = new MouseEventArgsEx(MouseButtons.None, x, y); // 这里是 实现 MouseEnter 事件 。 Windows 消息 中没有 MouseEnter 消息, 所以需要自己实现 // .Net WinForm 也是自己实现的, 不过 .Net WinForm 实现的方式是调用一些 Native 方法 // 比如 RegisterWindowMessage() TrackMouseEvent() // 这对于我们太复杂,我们只需要用 MouseMove 消息 和 MouseEventUtil 配合 就可以实现 Enter 事件 if (MouseEventUtil.SetEnter(c)) { if (form != null) { r = form.OnMouseEnterEx(new EventArgs()); } else if (ctrl != null) { r = ctrl.OnMouseEnterEx(new EventArgs()); } } // 如果 r == true , 则返回 true 终止事件冒泡 if (r) { return(true); } if (form != null) { r = form.OnMouseMoveEx(e); } else if (ctrl != null) { r = ctrl.OnMouseMoveEx(e); } // 如果 r == true , 则返回 true 终止事件冒泡 if (r) { return(true); } break; } case Win32.WM_LBUTTONDOWN: { // 实现 Click 事件,参考 MouseUp 消息处理部分 MouseEventUtil.SetClickDown(c); e = new MouseEventArgsEx(MouseButtons.Left, x, y); if (form != null) { r = form.OnMouseDownEx(e); } else if (ctrl != null) { r = ctrl.OnMouseDownEx(e); } // 如果 r == true , 则返回 true 终止事件冒泡 if (r) { return(true); } break; } case Win32.WM_LBUTTONUP: { e = new MouseEventArgsEx(MouseButtons.Left, x, y); // 这里是 实现 Click 事件 。 Windows 消息 中没有 MouseClick 消息 , 所以需要自己实现 // .Net WinForm 也是自己实现的。 if (MouseEventUtil.CheckClick(c, x, y)) { MouseEventUtil.SetClickUp(c); if (form != null) { r = form.OnMouseClickEx(e); } else if (ctrl != null) { r = ctrl.OnMouseClickEx(e); } } // 如果 r == true , 则返回 true 终止事件冒泡 if (r) { return(true); } if (form != null) { r = form.OnMouseUpEx(e); } else if (ctrl != null) { r = ctrl.OnMouseUpEx(e); } // 如果 r == true , 则返回 true 终止事件冒泡 if (r) { return(true); } break; } } return(false); }
private void Form360_MouseUpEx(object sender, MouseEventArgsEx e) { this.isResizing = false; }
private void MouseResize(MouseEventArgsEx e) { int oX; int oY; Point p = new Point(e.ScreenX, e.ScreenY); if (this.resizePosition == ResizePosition.RightBottom) { oX = p.X - this.resizeMouseOriginX; oY = p.Y - this.resizeMouseOriginY; this.Width = this.resizeOriginWidth + oX; this.Height = this.resizeOriginHeight + oY; } else if (this.resizePosition == ResizePosition.LeftTop) { oX = p.X - this.resizeMouseOriginX; oY = p.Y - this.resizeMouseOriginY; this.Width = this.resizeOriginWidth - oX; this.Height = this.resizeOriginHeight - oY; this.Left = this.resizeOriginLeft + oX; this.Top = this.resizeOriginTop + oY; } else if (this.resizePosition == ResizePosition.LeftBottom) { oX = p.X - this.resizeMouseOriginX; oY = p.Y - this.resizeMouseOriginY; this.Width = this.resizeOriginWidth - oX; this.Height = this.resizeOriginHeight + oY; this.Left = this.resizeOriginLeft + oX; } else if (this.resizePosition == ResizePosition.RightTop) { oX = p.X - this.resizeMouseOriginX; oY = p.Y - this.resizeMouseOriginY; this.Width = this.resizeOriginWidth + oX; this.Height = this.resizeOriginHeight - oY; this.Top = this.resizeOriginTop + oY; } else if (this.resizePosition == ResizePosition.Bottom) { oY = p.Y - this.resizeMouseOriginY; this.Height = this.resizeOriginHeight + oY; } else if (this.resizePosition == ResizePosition.Top) { oY = p.Y - this.resizeMouseOriginY; this.Height = this.resizeOriginHeight - oY; this.Top = this.resizeOriginTop + oY; } else if (this.resizePosition == ResizePosition.Right) { oX = p.X - this.resizeMouseOriginX; this.Width = this.resizeOriginWidth + oX; } else if (this.resizePosition == ResizePosition.Left) { oX = p.X - this.resizeMouseOriginX; this.Width = this.resizeOriginWidth - oX; this.Left = this.resizeOriginLeft + oX; } }
private void ShowResizeMouseCursor(MouseEventArgsEx e) { Point p = PointToClient(new Point(e.ScreenX, e.ScreenY)); int w = this.Content.Width; int h = this.Content.Height; int x = this.Content.Left; int y = this.Content.Top; int offset = this.resizeCornerOffset; // x1 y1 x2 y2 x3 y3 x4 y4 的 1 2 3 4 的 顺序 是 左上角 左下角 右下角 右上角 int x1 = x - offset; int y1 = y - offset; int x2 = x - offset; int y2 = y + h - 1 + offset; int x3 = x + w - 1 + offset; int y3 = y + h - 1 + offset; int x4 = x + w - 1 + offset; int y4 = y - offset; int c = this.resizeCornerSize; if (p.X >= x3 - c && p.X <= x3 && p.Y >= y3 - c && p.Y <= y3) { this.Cursor = Cursors.SizeNWSE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.RightBottom; } else if (p.X >= x1 && p.X <= x1 + c && p.Y >= y1 && p.Y <= y1 + c) { this.Cursor = Cursors.SizeNWSE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.LeftTop; } else if (p.X >= x2 && p.X <= x2 + c && p.Y >= y2 - c && p.Y <= y2) { this.Cursor = Cursors.SizeNESW; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.LeftBottom; } else if (p.X >= x4 - c && p.X <= x4 && p.Y >= y4 && p.Y <= y4 + c) { this.Cursor = Cursors.SizeNESW; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.RightTop; } else if (p.X >= x2 && p.X <= x3 && p.Y >= y2 - c && p.Y <= y2) { this.Cursor = Cursors.SizeNS; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Bottom; } else if (p.X >= x1 && p.X <= x4 && p.Y >= y1 && p.Y <= y1 + c) { this.Cursor = Cursors.SizeNS; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Top; } else if (p.X >= x1 && p.X <= x1 + c && p.Y >= y1 && p.Y <= y2) { this.Cursor = Cursors.SizeWE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Left; } else if (p.X >= x4 - c && p.X <= x4 && p.Y >= y4 && p.Y <= y3) { this.Cursor = Cursors.SizeWE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Right; } else { if (this.isMouseInResizeArea) { this.Cursor = Cursors.Default; this.isMouseInResizeArea = false; } } }