C# 窗体自动停靠隐藏
private void WindowShowHide() { if (this.WindowState == FormWindowState.Normal) { Point cursorPoint = new Point(Cursor.Position.X, Cursor.Position.Y); Rectangle rectgle = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); bool ptInRect = PtInRect(ref rectgle, cursorPoint); if (ptInRect) { if (this.Top < 0) { this.Top = 0; } else if (this.Left < 0) { this.Left = 0; } else if (this.Right > Screen.PrimaryScreen.WorkingArea.Width) { this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width; } } else { if (this.Top < 5) { this.Top = -this.Height + 5; } else if (this.Left < 5) { this.Left = -this.Width + 5; } else if (this.Right > Screen.PrimaryScreen.WorkingArea.Width - 5) { this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5; } } } }
private void CopyQQ_Move(object sender, EventArgs e) { WindowShowHide(); } private void CopyQQ_MouseMove(object sender, MouseEventArgs e) { WindowShowHide(); } private void CopyQQ_MouseLeave(object sender, EventArgs e) { WindowShowHide(); }