把窗口邊框去掉后,窗口拖動問題:
private Point mouseOffset; //記錄鼠標指針的坐標 private bool isMouseDown = false; //記錄鼠標按鍵是否按下 private void Form1_MouseDown(object sender, MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X - SystemInformation.FrameBorderSize.Width; yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void Form1_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void Form1_MouseUp(object sender, MouseEventArgs e) { // 修改鼠標狀態isMouseDown的值 // 確保只有鼠標左鍵按下並移動時,才移動窗體 if (e.Button == MouseButtons.Left) { isMouseDown = false; } }