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

Visual C++/CLI loading image added to resources to picturebox

我正在用 Visual C++ 编写一个 WinForm 应用程序,并将一些图像附加到资源中。这些图像都将在一个 PictureBox 中使用,我想通过单选按钮选择在它们之间切换。有用的东西

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

但我认为这直接从目录加载了图片。我不是 100% 确定,但我希望应用程序使用资源中的图像。

我已经只添加了 header #include "resource.h" 并且不知道下一步该做什么,因为在 MSDN 上没有如何执行此操作的信息。

我在另一个论坛上发现这个解决方案非常有效,您不要将图像添加到 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")));