在C#中使用鼠标移动移动控件

时间:2017-10-27 13:24:32

标签: c# mousemove

我想用C#鼠标移动一个按钮 我在stackoverflow上找到了这个解决方案

private Point MouseDownLocation;

private void MyControl_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        MouseDownLocation = e.Location;
    }
}

private void MyControl_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
    {
        (button)sender.Left = e.X + (button)sender.Left -MouseDownLocation.X;
        (button)sender.Top = e.Y + (button)sender.Top - MouseDownLocation.Y;
    }
}

我希望有人可以向我解释 有什么区别 e.X(这是mousemoving eventArgs的坐标)和MouseDownLocation.X

0 个答案:

没有答案