c# winform移动无标题栏窗体
Point mouseOffset;
bool isMouseDown;
private void Form1_MouseDown(object sender, MouseEventArgs e) {
int xOffset;
int yOffset;
if (e.Button == MouseButtons.Left) {
xOffset = -e.X;
yOffset = -e.Y;
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) {
if (e.Button == MouseButtons.Left) {
isMouseDown = false;
}
}