WordBreak in Stringridzellen

__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) 
{
    StringGrid1->DefaultDrawing = false;
}

void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, long Col, long Row, TRect &Rect, TGridDrawState State)
{
    if (State.Contains(gdFixed))
    {
       StringGrid1->Canvas->Brush->Color = clBtnFace;
       StringGrid1->Canvas->Font->Color = clWindowText;
       StringGrid1->Canvas->FillRect(Rect);
       Frame3D(StringGrid1->Canvas, Rect, clBtnHighlight, clBtnShadow, 1);
    }
    else if (State.Contains(gdSelected))
         {
            StringGrid1->Canvas->Brush->Color = clHighlight;
            StringGrid1->Canvas->Font->Color = clHighlightText;
            StringGrid1->Canvas->FillRect(Rect);
         }
         else
         {
             StringGrid1->Canvas->Brush->Color = StringGrid1->Color;
             StringGrid1->Canvas->Font->Color = StringGrid1->Font->Color;
             StringGrid1->Canvas->FillRect(Rect);
         }

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

    UINT format = DT_LEFT | DT_WORDBREAK;
    AnsiString text = StringGrid1->Cells[Col][Row];

    DrawText(StringGrid1->Canvas->Handle, text.c_str(), text.Length(), &Rect, format);
}

Schreibe einen Kommentar