Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;生成器/VCL,将图像添加到字符串网格_C++_Image_C++builder_Tstringgrid - Fatal编程技术网

C++ C++;生成器/VCL,将图像添加到字符串网格

C++ C++;生成器/VCL,将图像添加到字符串网格,c++,image,c++builder,tstringgrid,C++,Image,C++builder,Tstringgrid,你好,我有个问题。 我正在为我的毕业设计编写一个游戏,我一直在为StringGrid添加图像,这是一个2D益智游戏 我发现我必须在DrawCell上使用函数, 我试图编辑它,但我不知道它应该是什么样子,或者它到底是如何工作的 我想要的是:例如,如果我在单元格[0][0]中有字母“W”,我想显示墙的图片 我感谢你给予的任何帮助。在等待您的回答之前,我将在谷歌上搜索。在启动时,加载包含所需墙图片的图像。然后,在OnDrawCell事件处理程序中,检查网格的单元格值,如果检测到W,则Draw()网格的

你好,我有个问题。 我正在为我的毕业设计编写一个游戏,我一直在为StringGrid添加图像,这是一个2D益智游戏

我发现我必须在DrawCell上使用函数, 我试图编辑它,但我不知道它应该是什么样子,或者它到底是如何工作的

我想要的是:例如,如果我在单元格[0][0]中有字母“W”,我想显示墙的图片


我感谢你给予的任何帮助。在等待您的回答之前,我将在谷歌上搜索。

在启动时,加载包含所需墙图片的图像。然后,在
OnDrawCell
事件处理程序中,检查网格的
单元格
值,如果检测到
W
,则
Draw()
网格的
画布上的图像
。没有比这更简单的了

class TForm1 : public TForm
{
__published:
    TStringGrid *StringGrid1;
    void __fastcall StringGrid1DrawCell(TObject* Sender,
       int ACol, int ARow, const TRect &Rect, TGridDrawState State);
private:
    Graphics::TBitmap *WallBmp;
public:
    __fastcall TForm1(TComponent *Owner);
    __fastcall ~TForm1::TForm1();
};


你能告诉我们你试过什么吗?
__fastcall TForm1::TForm1(TComponent *Owner)
    : TForm(Owner)
{
    WallBmp = new Graphics::TBitmap;
    // fill image as needed - load a file or
    // a resource, hand draw directly on
    // WallBmp->Canvas, etc...
}

__fastcall TForm1::~TForm1()
{
    delete WallBmp;
}

void __fastcall TForm1::StringGrid1DrawCell(TObject* Sender,
    int ACol, int ARow, const TRect &Rect, TGridDrawState State)
{
    ...
    if (StringGrid1->Cells[ACol][ARow] == "W")
      StringGrid1->Canvas-Draw(WallBmp, Rect.Left, Rect.Top);
    ...
}