将 PictureBox 内的图片移动到另一个 PictureBox

发布于 2024-10-03 16:50:12 字数 76 浏览 0 评论 0原文

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

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

How can I move a picture that is inside a picturebox to another picturebox?

I want to use it for moving the pieces of chess game. I have a took picturebox for each place, so I have 64 pictureboxes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-10-10 16:50:12

您只需分配 将一个图片框中显示的图片复制到另一个图片框中。如果您随后想将图片从原图片框中删除(这样就不会显示两次),您可以设置其将 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;

You can just assign the Image displayed in one picture box to another picture box. If you then want to remove the image from the original picture box (so that it is not displayed twice), you can set its Image property to null (or, of course, you can assign any other image of your choice). Like so:

//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;

If you want to swap the images displayed in two picture boxes, you need to temporarily store one of the picture objects in a variable. So you can use very similar code, with a slight modification:

//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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文