1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int Col,
int Row, TRect &Rect, TGridDrawState State)
{
TCanvas *C = StringGrid1->Canvas;
AnsiString N = StringGrid1->Cells[Col][Row];
TRect Srce = Rect;
TRect Dest = Rect;
int he = StringGrid1->DefaultRowHeight;
int we = StringGrid1->DefaultColWidth;
Srce.Top -= he;
Srce.Bottom -= he;
C->CopyRect(Dest, Bitmap->Canvas, Srce);
TColor c = clBlack;
switch(Col)
{
case 1 : c = clBlue; break;
case 2 : c = clRed; break;
case 3 : c = clYellow; break;
case 5 : c = clWhite; break;
}
C->Font->Color = c;
int x = (we - C->TextWidth(N)) / 2;
int y = (he - C->TextHeight(N)) / 2;
C->Brush->Style = bsClear;
C->TextOut(Dest.Left + x, Dest.Top + y, N);
} |