0

I tried to do this:

void __fastcall TTetrisGame::DrawGrid1DrawCell(TObject *Sender, int ACol, int ARow,
    TRect &Rect, TGridDrawState State)
{
    this->Canvas->Brush->Color=clBlue;
    this->Canvas->FillRect(Rect);
}

But it is a really weird result. I put my StringGrid in the middle of the window but I can't see any Blue color. Instead, it is transparent. I see a colored blue Grid in the right top corner of my window.

What am I doing wrong?

How can I color each cell individually?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

2

You are painting on the wrong Canvas.

Inside your OnDrawCell event handler, this refers to the parent Form, because the handler is a member of the TTetrisGame class. As such, you are painting on the Form's Canvas. You need to paint on the Grid's Canvas instead:

void __fastcall TTetrisGame::DrawGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
    DrawGrid1->Canvas->Brush->Color=clBlue;
    DrawGrid1->Canvas->FillRect(Rect);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770