如何将图片框内的图片移动到另一个图片框?
我想用它来移动棋子。我有一个为每个地方拍摄的图片框,所以我有 64 个图片框。
最佳答案
您可以只分配 Image
在一个图片框中显示到另一个图片框。如果您随后想从原始图片框中删除图像(这样它就不会显示两次),您可以设置其 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;
关于c# - 将 PictureBox 中的图片移动到另一个 PictureBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4243162/