简体   繁体   English

将Visual C ++ / CLI加载图像添加到图片框资源

[英]Visual C++/CLI loading image added to resources to picturebox

I am writing a WinForm application in Visual C++ and I attached some images to resources. 我正在用Visual C ++编写WinForm应用程序,并将一些图像附加到资源上。 Those images will all be used in one PictureBox and I want to switch between them via radiobutton selection. 这些图像将全部用在一个PictureBox中,我想通过单选按钮在它们之间切换。 The thing that worked 起作用的东西

void newton(void)
    {
        rheomod = 1;
        pictureBox1->Image = Image::FromFile("newton.png");
    }

but I think this loaded the pictures directly from the directory. 但是我认为这直接从目录加载了图片。 I'm not 100% sure but I would like the app to use the images from resources. 我不确定100%,但是我希望该应用使用资源中的图像。

I already added only the header #include "resource.h" and don't know what to do next, because on MSDN there is no info how to do this. 我已经只添加了头文件#include "resource.h"并且不知道下一步该怎么做,因为在MSDN上没有信息。

I found on another forum this solution which works really fine, you don't add the image to resource.resx but to MyForm.resx then the code: 我在另一个论坛上发现此解决方案确实有效,您无需将图像添加到resource.resx,而是将代码添加到MyForm.resx,然后添加代码:

        delete pictureBox1->Image;
        System::ComponentModel::ComponentResourceManager^  resources = (gcnew
            System::ComponentModel::ComponentResourceManager(MyForm::typeid));
        pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"newton")));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM