日期:2014-05-18 浏览次数:21021 次
bool isStart1,isStart2; int mx, my, cx, cy; //以下三个方法为picture1的移动方法 private void picture1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isStart1 = true; mx = e.X; my = e.Y; } } private void picture1_MouseMove(object sender, MouseEventArgs e) { if (isStart1) { cx = picture1.Left - mx + e.X; cy = picture1.Top - my + e.Y; picture1.Left = cx; picture1.Top = cy; } } private void picture1_MouseUp(object sender, MouseEventArgs e) { isStart1 = false; } //以下三个方法为picture2的移动方法 private void picture2_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isStart2 = true; mx = e.X; my = e.Y; } } private void picture2_MouseMove(object sender, MouseEventArgs e) { if (isStart2) { cx = picture2.Left - mx + e.X; cy = picture2.Top - my + e.Y; picture2.Left = cx; picture2.Top = cy; } } private void picture2_MouseUp(object sender, MouseEventArgs e) { isStart2 = false; }
------解决方案--------------------
设一个bool[] b=new bool[pictureBox的数量];
都为false
当MouseDown时.将b[pictureBox对应的 ]=true;
当MouseUp时 将 b[pivturebox对应的]=false;
MouseMove事件中,判断其对应的 变量是true才动, 是false就不动.
------解决方案--------------------
你把mx,my,cx,cy也定义两个就ok了
bool isStart1,isStart2; int mx1, my1, cx1, cy1; int mx2, my2 cx2, cy2; //以下三个方法为picture1的移动方法 private void picture1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isStart1 = true; mx1 = e.X; my1 = e.Y; } } private void picture1_MouseMove(object sender, MouseEventArgs e) { if (isStart1) { cx1 = picture1.Left - mx1 + e.X; cy1 = picture1.Top - my1 + e.Y; picture1.Left = cx1; picture1.Top = cy1; } } private void picture1_MouseUp(object sender, MouseEventArgs e) { isStart1 = false; } //以下三个方法为picture2的移动方法 private void picture2_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isStart2 = true; mx2 = e.X; my2 = e.Y; } } private void picture2_MouseMove(object sender, MouseEventArgs e) { if (isStart2) { cx2 = picture2.Left - mx2 + e.X; cy2 = picture2.Top - my2 + e.Y; picture2.Left = cx2; picture2.Top = cy2; } } private void picture2_MouseUp(object sender, MouseEventArgs e)