TStringGrid组件改变单元格色彩
TStringGrid组件改变单元格颜色
请教如何改变TStringGrid单元格的颜色。
------解决方案--------------------
服了你了。意思就是在StringGrid的OnDrawCell事件中,把代码写进去,类似这样:
------解决方案--------------------
请教如何改变TStringGrid单元格的颜色。
------解决方案--------------------
服了你了。意思就是在StringGrid的OnDrawCell事件中,把代码写进去,类似这样:
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid *sg = dynamic_cast <TStringGrid *> (Sender);
if (sg)
{
String strText = sg->Cells[ACol][ARow];
sg->Canvas->Font->Color = clRed;
sg->Canvas->FillRect(Rect);
::DrawText(sg->Canvas->Handle,
strText.c_str(),
-1,
(RECT *)&(TRect(Rect.left + 2, Rect.top, Rect.right - 2, Rect.bottom)),
DT_SINGLELINE
------解决方案--------------------
DT_VCENTER
------解决方案--------------------
DT_LEFT
------解决方案--------------------
DT_WORDBREAK);
}
}
------解决方案--------------------