Andaç Temel
Andaç Temel

Reputation: 216

Windows Forms:picture box manual drag operation over image solution?

Hi I write a code that will dragginging picture box in winform this is my code:

   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);

           }

       }
   }

and I have same code for picturebox 2, my question is: when I am dragging my first picture to second one it goes over it and code work properly,but while ı am dragging second picture box to first picture box , second picture box goes under the first one ! is there a property for this?

Upvotes: 4

Views: 520

Answers (1)

max
max

Reputation: 34417

You can use BringToFront() method:

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

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

Upvotes: 3

Related Questions