3

flowLayout パネルに 2 つの pictureBox があり、pictureBox1 を pictureBox2 の位置に移動し、pictureBox2 を pictureBox1 の位置に移動する必要があります。

編集:

私は試しましたが、pictureBoxesは移動しません...位置を確認するためにMessageBoxを使用しました..位置は正しいですが、位置を交換しません(位置は変更されていません...)

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

6 に答える 6

8

pictureBoxコンテナー コントロール ( ) 内の子コントロール ( ) のインデックスを設定することで、順序を変更できますflowLayoutPanel

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

flowLayoutPanel1.Controls.SetChildIndex(pictureBox1, index2);
flowLayoutPanel1.Controls.SetChildIndex(pictureBox2, index1);
于 2013-02-27T13:13:49.300 に答える
1

関数を作成できます

public void SwapLocations(ref Point p1, ref Point p2)
{
    Point temp = p1;
    p1 = p2;
    p2 = temp;
}

それからそれを呼び出します

SwapLocations(pictureBox1.Location, pictureBox2.Location);
于 2013-02-27T13:11:12.247 に答える
0
Point loc1 = pictureBox1.Location;
Point loc2 = pictureBox2.Location;

pictureBox1.Location = loc2;
pictureBox2.Location = loc1;

編集: 1 つのポイント割り当て:

Point temp = pictureBox1.Location;

pictureBox1.Location = pictureBox2.Location;
pictureBox2.Location = temp;
于 2013-02-27T13:05:52.903 に答える
0

それらの位置を交換したい場合は、それらのLocationプロパティを交換するだけです:

int tmp_X = p1.Location.X;
int tmp_Y = p1.Location.Y;

p1.Location.X = p2.Location.X;
p1.Location.Y = p2.Location.Y;

p2.Location.X = tmp_X;
p2.Location.Y = tmp_Y;

視覚的な再配置を強制するには、次のコマンドを呼び出します。

p1.Invalidate();
p2.Invalidate();
于 2013-02-27T13:12:01.540 に答える