Image resources?

五迷三道 提交于 2019-12-12 02:14:52

问题


I've been struggling for hours trying to figure out how to use resources in C++/CLI. I've messed around with the resource.h/app.rc files along with the managed resx files to no avail.

I just have a couple PNG images that I would like to use with a PictureBox, but I can't seem to figure out how to setup the resources...

Thanks for your help,

Alex


回答1:


  • create a windows forms project
  • add new resource file (resx) to the project
  • open that file, the resource editor appears
  • in the top left corner switch to image mode
  • at the top click to "Add resources", and add your images
  • in your code use it this way:

    using namespace System::Resources;
    
    ResourceManager^ rm = gcnew ResourceManager("ImageResources.MyResources", GetType()->Assembly);
    
    pictureBox1->Image = safe_cast<Image^>(rm->GetObject(L"MyImage");
    

Where "ImageResources" is the name of the namespace, the "MyResources" is the name of the resx file and the "MyImage" is the name of the image inside the resource file.



来源:https://stackoverflow.com/questions/11894112/image-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!