【问题标题】:Moving a picture that is inside a PictureBox to another PictureBox将 PictureBox 中的图片移动到另一个 PictureBox
【发布时间】:2010-11-22 07:21:06
【问题描述】:

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

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

【问题讨论】:

    标签: c# .net winforms picturebox


    【解决方案1】:

    您可以将一个图片框中显示的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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多