如何在两个图片框之间交换图像/图像文件。 [英] How to swap the images/image files between two pictureboxes.

查看:83
本文介绍了如何在两个图片框之间交换图像/图像文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试交换两个图片框的图像。我正在尝试为学校项目制作滑动瓷砖图片益智游戏(使用visual studio,visual c ++,win。表单应用程序)。现在,我不知道为什么它不会交换。我为picturebox(picbox9)创建了一个click
事件,当我点击picbox9 picturebox时,它将无法正常工作。任何人都可以帮助我吗?

I'm trying to swap the images of two picture boxes. I'm trying to make a sliding tile picture puzzle game for a school project (using visual studio, visual c++, win. forms application). Right now, I don't know why it won't swap. I've created a click event for the picturebox (picbox9), and when I click on picbox9 picturebox, it won't work. Can anyone help me?


这是代码#pragma endregion

Here's the code #pragma endregion

    private: System::Void btnload_Click(System::Object^  sender,
    System::EventArgs^  e) {
            picbox1->Image=Image::FromFile("pic1.jpg");
            picbox2->Image=Image::FromFile("pic2.jpg");
            picbox3->Image=Image::FromFile("pic3.jpg");
            picbox4->Image=Image::FromFile("pic4.jpg");
            picbox5->Image=Image::FromFile("pic5.jpg");
            picbox6->Image=Image::FromFile("pic6.jpg");
            picbox7->Image=Image::FromFile("pic7.jpg");
            picbox8->Image=Image::FromFile("pic8.jpg");
            picbox9->Image=Image::FromFile("pic9.jpg");
            picboxnull->Image=Image::FromFile("null.jpg");
     }


     private: System::Void picbox9_Click(System::Object^  sender,
    System::EventArgs^  e) {
        if(picboxnull->Image==Image::FromFile("null.jpg"))
        { 
            picboxnull->Image=Image::FromFile("pic9.jpg");
            picbox9->Image=Image::FromFile("null.jpg");
        }



    }
   };

   }




推荐答案

您好AnjeroX,

Hi AnjeroX,

感谢您在此处发布。

>>我正在尝试交换两个图片框的图片。我正在尝试为学校项目制作滑动瓷砖图片益智游戏(使用visual studio,visual c ++,win。表单应用程序)。现在,我不知道为什么它不会交换。我为
创建了一个用于图片框的点击事件(picbox9),当我点击picbox9图片框时,它将无法正常工作。任何人都可以帮助我吗?

文件保持锁定,直到
图像
被处理掉。您是否尝试使用Image :: Dispose方法来选择性地释放托管资源。然后调用Image :: FromFile 方法加载图像?

The file remains locked until the Image is disposed. Have you tried to use Image::Dispose Method to optionally releases the managed resources. Then call Image::FromFile method to load the image?

您还应该注意到在释放对图像的最后一个引用之前需要调用Dispose 。否则,在垃圾收集器调用Image对象的Finalize方法之前,它将使用的资源不会被释放。

You should also notice that you need to call Dispose before you release your last reference to the Image. Otherwise, the resources it is using will not be freed until the garbage collector calls the Image object's Finalize method.

希望这可以帮到你。

最诚挚的问候,

Sera Yu


这篇关于如何在两个图片框之间交换图像/图像文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆