C# 将PictureBox中的图片移动到另一个PictureBox

C# 将PictureBox中的图片移动到另一个PictureBox,c#,.net,winforms,picturebox,C#,.net,Winforms,Picturebox,如何将picturebox中的图片移动到另一个picturebox 我想用它来移动棋子。每个地方我都有一个已拍摄的图片框,所以我有64个图片框。您可以将一个图片框中显示的图片框分配给另一个图片框。如果您想从原始图片框中删除图像(这样它就不会显示两次),您可以将其image属性设置为null(当然,您也可以指定您选择的任何其他图像)。例如: //Assign the image in one picture box to another picture box mySecondPicBox.Ima

如何将picturebox中的图片移动到另一个picturebox


我想用它来移动棋子。每个地方我都有一个已拍摄的图片框,所以我有64个图片框。

您可以将一个图片框中显示的图片框分配给另一个图片框。如果您想从原始图片框中删除图像(这样它就不会显示两次),您可以将其
image
属性设置为
null
(当然,您也可以指定您选择的任何其他图像)。例如:

//Assign the image in one picture box to another picture box
mySecondPicBox.Image = myFirstPicBox.Image;

//Clear the image from the original picture box
myFirstPicBox.Image = null;

如果要交换显示在两个图片框中的图像,需要将其中一个图片对象临时存储在一个变量中。因此,您可以使用非常类似的代码,只需稍加修改:

//Temporarily store the picture currently displayed in the second picture box
Image secondImage = mySecondPicBox.Image;

//Assign the image from the first picture box to the second picture box
mySecondPicBox.Image = myFirstPicBox.Image;

//Assign the image from the second picture box to the first picture box
myFirstPicBox.Image = secondImage;

您只需将一个图片框中显示的图像分配给另一个图片框。如果您想从原始图片框中删除图像(这样它就不会显示两次),您可以将其
image
属性设置为
null
(当然,您也可以分配您选择的任何其他图像)。例如:

//Assign the image in one picture box to another picture box
mySecondPicBox.Image = myFirstPicBox.Image;

//Clear the image from the original picture box
myFirstPicBox.Image = null;

如果要交换显示在两个图片框中的图像,需要将其中一个图片对象临时存储在一个变量中。因此,您可以使用非常类似的代码,只需稍加修改:

//Temporarily store the picture currently displayed in the second picture box
Image secondImage = mySecondPicBox.Image;

//Assign the image from the first picture box to the second picture box
mySecondPicBox.Image = myFirstPicBox.Image;

//Assign the image from the second picture box to the first picture box
myFirstPicBox.Image = secondImage;