Windows Forms: manual drag and drop operation compared to image solution?

Hi, I am writing code that will drag the image window into winform, this is my code:

private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { pictureBox1.Top=(56 * ((pictureBox1.Top + (eY - 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 = eX; firsty = eY; 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 + (eY - firsty) < 0) { pictureBox1.Top = 0;//these are the limits of dragging } else if (pictureBox1.Location.Y + (eY - firsty) > 290) { pictureBox1.Top = 290;//these are the limits of dragging } else { pictureBox1.Top = pictureBox1.Top + (eY - firsty); } if (pictureBox1.Location.X + (eX - firstx) < 6) { pictureBox1.Left = 6;//these are the limits of dragging } else if (pictureBox1.Location.X + (eX - firstx) > 280) { pictureBox1.Left = 280;//these are the limits of dragging } else { pictureBox1.Left = pictureBox1.Left + (eX - firstx); } } } 

and I have the same code for picturebox 2, my question is: when I drag my first picture into the second, it looks through it and the code works correctly, but for now I drag the second box for the image into the first box with pictures, the second box with a picture goes under the first! is there a property for this?

+4
source share
1 answer

You can use the BringToFront() method:

 private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { pictureBox1.BringToFront(); /**/ } private void pictureBox2_MouseDown(object sender, MouseEventArgs e) { pictureBox2.BringToFront(); /**/ } 
+3
source

Source: https://habr.com/ru/post/1494475/


All Articles