4

嗨我写了一个代码,将在winform中拖动图片框这是我的代码:

   private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
   {

       pictureBox1.Top=(56 * ((pictureBox1.Top + (e.Y - firsty)) / 56) + 3); //this for the correction of location of picture box
       isdragging[0] = false;

    }
     private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
   {
       isdragging[0] = true;
       firstx = e.X;
       firsty = e.Y;
       changeclickingstatus(pictureBox1);//this about my program
       for (sbyte i = 0; i < (sbyte)20; i++)//this about my program
       {
           clickindex[i] = (sbyte)1;//this about my program
       }
       clickindex[0] = (sbyte)0;//this about my program
       dragtop = (sbyte)(pictureBox1.Top/56);//this about my program
       }



        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
       {
       if (isdragging[0])
       {

           if (pictureBox1.Location.Y + (e.Y - firsty) < 0)
           {
               pictureBox1.Top = 0;//these are the limits of dragging

           }
           else if (pictureBox1.Location.Y + (e.Y - firsty) > 290)
           {
               pictureBox1.Top = 290;//these are the limits of dragging

           }
           else
           {



               pictureBox1.Top = pictureBox1.Top + (e.Y - firsty);

           }


           if (pictureBox1.Location.X + (e.X - firstx) < 6)
           {
               pictureBox1.Left = 6;//these are the limits of dragging
           }
           else if (pictureBox1.Location.X + (e.X - firstx) > 280)
           {
               pictureBox1.Left = 280;//these are the limits of dragging
           }
           else
           {
               pictureBox1.Left = pictureBox1.Left + (e.X - firstx);

           }

       }
   }

我对图片框 2 有相同的代码,我的问题是:当我将第一张图片拖到第二张图片时,它会越过它并且代码可以正常工作,但是当我将第二个图片框拖到第一个图片框时,第二个图片框在下面第一个 !有这个属性吗?

4

1 回答 1

3

您可以使用BringToFront()方法:

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    pictureBox1.BringToFront();
    /**/
}

private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
    pictureBox2.BringToFront();
    /**/
}
于 2013-07-31T11:31:48.367 回答