Point _downPoint;
private void button1_MouseDown(object sender, MouseEventArgs e)
{
_downPoint = new Point(e.X, e.Y);
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Control ctr = sender as Control;
ctr.Location = new Point(ctr.Location.X + e.X - _downPoint.X, ctr.Location.Y + e.Y - _downPoint.Y);
}
}
本文介绍了一种在按钮上实现鼠标拖动效果的方法。通过监听MouseDown和MouseMove事件,记录鼠标按下位置,并在鼠标移动时更新按钮的位置,实现拖拽功能。
2312





