【发布时间】:2010-11-22 07:21:06
【问题描述】:
如何将图片框内的图片移动到另一个图片框?
我想用它来移动棋子。每个地方我都有一个拍摄的图片框,所以我有 64 个图片框。
【问题讨论】:
标签: c# .net winforms picturebox
如何将图片框内的图片移动到另一个图片框?
我想用它来移动棋子。每个地方我都有一个拍摄的图片框,所以我有 64 个图片框。
【问题讨论】:
标签: c# .net winforms picturebox
您可以将一个图片框中显示的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;
【讨论】: