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

标签 c# .net winforms picturebox

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

我想用它来移动棋子。我有一个为每个地方拍摄的图片框,所以我有 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/

相关文章:

c# - 微软消息队列和资源发布最佳实践

c# - 注入(inject)通用的 getter 和 setter 以获得比反射更好的性能

c# - 将 WinForms 窗体设置为 WPF 窗口的所有者

c# - 使用 C# 创建动态按钮并按预定义的顺序放置它们

c# - 重新注入(inject)新反序列化对象的依赖项

c# - 使报表查看器可滚动

c# - 单元测试使用静态变量的 C#/.NET 类(单元测试进程隔离)

.net - 如何测试 WPF 用户界面?

.net - 在 Lucene 中获取文档 ID

c# - 如何向 SQL 参数提供 List<int>?