在C#中實(shí)現(xiàn)框架窗口的拖拽操作,可以通過(guò)以下步驟實(shí)現(xiàn):
private Point mouseOffset;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
mouseOffset = new Point(-e.X, -e.Y);
this.Capture = true;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
this.Location = mousePos;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
this.Capture = false;
}
通過(guò)以上步驟,就可以實(shí)現(xiàn)框架窗口的拖拽操作。當(dāng)用戶按下鼠標(biāo)左鍵并拖動(dòng)窗口時(shí),窗口會(huì)跟隨鼠標(biāo)移動(dòng)。