日期:2014-05-18  浏览次数:21021 次

C#winform中放有多个picturebox控件,如何让称动一个时,其它的不动?
在一个窗口里,加入了多个picturebox控件,如picture1,picture2,当我拖动picture1时,在没有经过picture2时,正常的,也就是只有picture1动,可当我将其拖动到picture2上面时,picture2就跟着一起动了,反过来拖picture2时也一样,当经过picture1时,二个也一起动了,请问如何才能让其经过时,只动拖动的那个,另一个不动呀,请高手指点..
在线等,多谢谢了,最好给点源代码提示....解决马上结帖给分...

------解决方案--------------------
isStart要定义两个变量

IsPicture1Start, IsPicture2Start分别记录Picture1和Picture2移动
就可以了
------解决方案--------------------
C# code

 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了


C# code
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)