604
社区成员
发帖
与我相关
我的任务
分享
void __fastcall TEhGridDbDemoFrom::ProcGridDrawColumnCell(TObject *Sender, const TRect &Rect,
int DataCol, TColumnEh *Column, Gridseh::TGridDrawState State)
{
if (Column->FieldName != "ReorderPoint") return;
TDBGridEh *DBGrid1 = dynamic_cast <TDBGridEh *>(Sender);
String DrawText = FormatFloat("0.00",DBGrid1->Fields[3]->AsCurrency); //Column->Field->AsCurrency
DrawText = StringReplace(DrawText, ".", "", TReplaceFlags() << rfReplaceAll);
bool BoolFZ = DrawText.SubString(1, 1) == "-";
DBGrid1->Canvas->Brush->Color = clWhite;
DBGrid1->Canvas->FillRect(Rect);
DBGrid1->Canvas->Font->Color = clBlack;
int SubTextWidth;
int LineLeft, SubTextLeft, SubTextTop;
String DrawSubText;
for (int I = 1; I < 20; I++)
{
switch(I)
{
case 3:
DBGrid1->Canvas->Pen->Color = clRed;
break;
case 1:
case 6:
case 9:
case 12:
case 15:
case 18:
DBGrid1->Canvas->Pen->Color = clGreen;
break;
default:
DBGrid1->Canvas->Pen->Color = clGrayText;
break;
}
SubTextWidth = DBGrid1->Canvas->TextWidth("0") + 4;
if (BoolFZ)
{
if (I > DrawText.Length())
DrawSubText = "";
else
DrawSubText = DrawText.SubString(DrawText.Length() - I + 2, 1);
}
else
{
if (I > DrawText.Length())
DrawSubText = "";
else
DrawSubText = DrawText.SubString(DrawText.Length() - I + 1, 1);
}
//
LineLeft = Rect.Right - SubTextWidth * (I - 1);
SubTextLeft = LineLeft - SubTextWidth + 2;
SubTextTop = Rect.Top + (Rect.Bottom - Rect.Top - DBGrid1->Canvas->TextHeight("0")) / 2;
if (BoolFZ)
DBGrid1->Canvas->Font->Color = clRed;
DBGrid1->Canvas->TextOut(SubTextLeft, SubTextTop, DrawSubText);
DBGrid1->Canvas->MoveTo(LineLeft, Rect.Top);
DBGrid1->Canvas->LineTo(LineLeft, Rect.Bottom);
}
}