C#窗体编程中如何让鼠标右键拖着图片动态的移动?当鼠标停时图片也停下来?求救?
2个回答
展开全部
private Point mouse_offset;
private void MoveCar_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void MoveCar_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Point mousepos = Control.MousePosition;
mousepos.Offset(mouse_offset.X,mouse_offset.Y);
//------设定图片新位置-------------------------------------
pic.left = mousepos.X;
pic.top = mousepos.Y;
//----------------------------------------------------------------
}
}
private void MoveCar_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void MoveCar_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
Point mousepos = Control.MousePosition;
mousepos.Offset(mouse_offset.X,mouse_offset.Y);
//------设定图片新位置-------------------------------------
pic.left = mousepos.X;
pic.top = mousepos.Y;
//----------------------------------------------------------------
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询