Título: StringGrid
Linguagem: C++Builder
S.O.: Windows
Autor(es): Cássius Adriano Firion


StringGrid

Rotina: Mudar a cor da fonte de uma célula do StringGrid.

Código Fonte:

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, long Col, long Row, TRect &Rect, TGridDrawState State)
{
  const  CharOffset = 3;
  StringGrid1->Canvas->Font->Color = clMaroon; //muda a cor para marrom
  StringGrid1->Canvas->TextOut(Rect.Left + CharOffset, Rect.Top + CharOffset, 'B');//escreve o  'B'
  StringGrid1->Canvas->Font->Color = clNavy; //muda a cor para navy
  StringGrid1->Canvas->TextOut(Rect.Left + CharOffset + Canvas->TextWidth('B'), Rect.Top + CharOffset, "orland");    //imprime o  'orland'

}
Rotina: Borda colorida de uma célula. Código Fonte:
void MarkCell(int iCol, int iRow, TColor tcColor, int iGraf)
{
  RECT r;
  int iTamCol, iTamRow;

  iTamCol = StringGrid1->DefaultColWidth + 1;
  iTamRow = StringGrid1->DefaultRowHeight + 1;

  r.left   = iTamCol * iCol;
  r.top    = iTamRow * iRow;
  r.right  = iTamCol * iCol + iTamCol;
  r.bottom = iTamRow * iRow + iTamRow;

  StringGrid1->Canvas->Font->Color = clBlack;
  StringGrid1->Canvas->Pen->Color = tcColor;
  StringGrid1->Canvas->Pen->Width = 2;
  StringGrid1->Canvas->Rectangle(r.left, r.top, r.right, r.bottom);
  StringGrid1->Canvas->TextOut(r.left + 2, r.top + 2, StringGrid1->Cells[iCol][iRow]);
}

1