项目资源

Resources of project

本文关键字:资源 项目      更新时间:2023-10-16

我需要在文件中更改图片框的图像。h,我写这本书:

mass[oldcord.first - 1, oldcord.second + 1]->Image = Image::FromFile("EMPTY.png");

但是,如果我不是从文件夹中运行项目,我会遇到一个错误,因为如果找不到图像,因为我不是从项目文件夹中执行它。我如何使用"资源"不是从我的表单中使用的,而是从这样的其他文件中使用:

this->MainField->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"Field")));

我希望我的应用程序从任何地方执行,不仅是从我的文件夹中执行的。

我试图通过构造函数传递形式资源,但是我失败了

加法:

#pragma once
#include "MainForm.h"
#include <string>
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
enum TYPE { EMPTY, BLACK, WHITE };
ref class Figure
{
public:
    Figure()
    {
        color = EMPTY;
        active = 0;
        king = 0;
    }
    Figure(int x, int y, TYPE color)
    {
        this->color = color;
        this->color = color;
        active = 0;
        king = 0;
    }
    void MoveTo(pair<int,int> newcord, System::Windows::Forms::PictureBox^ current, TYPE turn) // ставит на место, меняет статус, цвет
    {
        current->Location = System::Drawing::Point(37 + newcord.second * 90, 37 + newcord.first * 90);
        if (color == EMPTY)
            color = turn;
        else
            color = EMPTY;
    }
    void make_king(System::Windows::Forms::PictureBox^% current, int i)
    {
        if (i == 0 && color == WHITE)
        {
            current->Image = Image::FromFile("WhiteKing.png");
            king = true;
        }
        else if (i == 7 && color == BLACK)
        {
            current->Image = Image::FromFile("BlackKing.png");
            king = true;
        }
    }
    bool is_active()
    {
        return active;
    }
    void make_active(bool active)
    {
        this->active = active;
    }
    TYPE getColor()
    {
        return color;
    }
    void setColor(TYPE color)
    {
        this->color = color;
    }
    bool is_king()
    {
        return king;
    }
private:
    Graphics^ picture;
    TYPE color;
    bool active;
    bool king;
};

您可以尝试使用boost :: program_options为此>

例如,您的程序可以拥有一个配置类,该类别具有可以在运行时间更改的配置选项(例如带有资源或任何您需要的路径(。