Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the position of an PictureBox

I have 2 pictureBoxes on a flowLayout Panel and need move the pictureBox1 to pictureBox2's position and pictureBox2 to pictureBox1's position

EDIT:

I have tried but the pictureBoxes dont move...I have used MessageBox for check the positions..and the positions are right but they dont swap the position(the locations not changed...)

     MessageBox.Show("PixBoxMover x " + picBoxMover.Location.X + "y " + picBoxMover.Location.Y);
        MessageBox.Show("picBoxMovendo x " + picBox.Location.X + "y " + picBox.Location.Y);

        Point temp = picBox.Location;

        picBox.Location = picBoxMover.Location;
        picBoxMover.Location = temp;

        MessageBox.Show("PixBoxMover x " + picBoxMover.Location.X + "y " + picBoxMover.Location.Y);
        MessageBox.Show("picBoxMovendo x " + picBox.Location.X + "y " + picBox.Location.Y);
like image 926
Ladessa Avatar asked Nov 25 '25 14:11

Ladessa


1 Answers

You can change the ordering by setting the index of the child control (pictureBox) within the container control (flowLayoutPanel):

var index1 = flowLayoutPanel1.Controls.IndexOf(pictureBox1);
var index2 = flowLayoutPanel1.Controls.IndexOf(pictureBox2);

flowLayoutPanel1.Controls.SetChildIndex(pictureBox1, index2);
flowLayoutPanel1.Controls.SetChildIndex(pictureBox2, index1);
like image 92
Oliver Avatar answered Nov 27 '25 04:11

Oliver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!