StringGrid Zellen einfärben/Text ausrichten

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
     TStringGrid *Grid = (TStringGrid *)Sender;
     int hAlign = DT_CENTER;

     Grid->Canvas->Font->Color = clBlack;

     switch (ACol)
     {
            case 0 : { if (ARow != 0)
                       {
                           hAlign = DT_RIGHT;
                       }

                       Grid->Canvas->Font->Style = TFontStyles() << fsBold;

                       break; }
            case 1 : { if (ARow == 0)
                       {
                          Grid->Canvas->Font->Style = TFontStyles() << fsBold;
                       }
                       else
                       {
                           hAlign = DT_LEFT;
                       }

                       break; }
     }

     if (State.Contains(gdFocused)) // wenn Zelle focusiert
     {
         Grid->Canvas->Brush->Color = clYellow; // gelbe Zelle
     }

     Grid->Canvas->FillRect(Rect); // Hintergrund übermalen

     DrawText(Grid->Canvas->Handle, Grid->Cells[ACol][ARow].c_str(), -1, &amp;Rect, DT_SINGLELINE | DT_VCENTER | hAlign);
}

Schreibe einen Kommentar