在StringGrid中怎么实现某一单元格内的文字换行
1个回答
推荐于2018-04-05
展开全部
试试这个能不能实现,通过自画的方式在单元格内画出文字
控件使用-StringGrid多行显示超长文字
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TRect ARect; //paint cell range
ARect = StringGrid1-> CellRect(ACol,ARow);
AnsiString CurrStr = StringGrid1-> Cells[ACol][ARow] ;
if (CurrStr.Length() <10)
{
//StringGrid1-> Canvas-> Brush-> Color = clRed ;//Setting Cell color
//StringGrid1-> Canvas-> FillRect(ARect);
//StringGrid1-> Canvas-> Font-> Color = clBlack;//Setting Cell Contents Font Color
StringGrid1-> Canvas-> TextRect(ARect,ARect.Left+2,ARect.Top+2,StringGrid1-> Cells[ACol][ARow]);
}
else
{
//StringGrid1-> Canvas-> Brush-> Color = clWhite;
//StringGrid1-> Canvas-> FillRect(ARect);
//StringGrid1-> Canvas-> Font-> Color = clBlack;
StringGrid1-> Canvas-> TextOut(ARect.Left+2,ARect.Top+2,StringGrid1-> Cells[ACol][ARow].SubString(1,10));
StringGrid1-> Canvas-> TextOut(ARect.Left+2,ARect.Top+17,StringGrid1-> Cells[ACol][ARow].SubString(11,20));
}
}
控件使用-StringGrid多行显示超长文字
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TRect ARect; //paint cell range
ARect = StringGrid1-> CellRect(ACol,ARow);
AnsiString CurrStr = StringGrid1-> Cells[ACol][ARow] ;
if (CurrStr.Length() <10)
{
//StringGrid1-> Canvas-> Brush-> Color = clRed ;//Setting Cell color
//StringGrid1-> Canvas-> FillRect(ARect);
//StringGrid1-> Canvas-> Font-> Color = clBlack;//Setting Cell Contents Font Color
StringGrid1-> Canvas-> TextRect(ARect,ARect.Left+2,ARect.Top+2,StringGrid1-> Cells[ACol][ARow]);
}
else
{
//StringGrid1-> Canvas-> Brush-> Color = clWhite;
//StringGrid1-> Canvas-> FillRect(ARect);
//StringGrid1-> Canvas-> Font-> Color = clBlack;
StringGrid1-> Canvas-> TextOut(ARect.Left+2,ARect.Top+2,StringGrid1-> Cells[ACol][ARow].SubString(1,10));
StringGrid1-> Canvas-> TextOut(ARect.Left+2,ARect.Top+17,StringGrid1-> Cells[ACol][ARow].SubString(11,20));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询