1. 程式人生 > >C# 鼠標點擊移動窗體代碼,可以實現無邊框窗體的拖動

C# 鼠標點擊移動窗體代碼,可以實現無邊框窗體的拖動

點擊 obj cat += tar sender see sed false

private static bool IsDrag = false;
private int enterX;
private int enterY;
private void setForm_MouseDown(object sender, MouseEventArgs e)
{
IsDrag = true;
enterX = e.Location.X;
enterY = e.Location.Y;
}

private void setForm_MouseUp(object sender, MouseEventArgs e)
{
IsDrag = false;
enterX = 0;
enterY = 0;
}

private void setForm_MouseMove(object sender, MouseEventArgs e)
{
if (IsDrag)
{
Left += e.Location.X - enterX;
Top += e.Location.Y - enterY;
}
}

C# 鼠標點擊移動窗體代碼,可以實現無邊框窗體的拖動