大家好,又见面了,我是你们的朋友全栈君。
procedure TformBuy.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
var
S: String;
i, x, y, iTextWidth: Integer;
begin
// if Field.DataType <> ftBCD then Exit;
if Field.FieldName <> ‘jxdmoney’ then Exit;
with TDBGrideh(Sender).Canvas do
begin
iTextWidth := TextWidth(‘8’) + 4;
y := Rect.Top + (Rect.Bottom – Rect.Top – TextHeight(‘8’)) div 2;
S := StringReplace(FormatFloat(‘0.00’, Field.AsCurrency), ‘.’, ”, []);
if Field.AsCurrency < 0 then Font.Color := clRed;
FillRect(Rect);
i := (Rect.Right – Rect.Left) div iTextWidth;
repeat
x := Rect.Right – iTextWidth * i;
if i <= Length(S) then
TextOut(x+3, y, S[Length(S)-i+1]);
if i = 2 then
Pen.Color := clRed
else if (i = 0) or ( (i>2) and (((i-2) mod 3) = 0) ) then
Pen.Color := clGreen
else
Pen.Color := clSilver;
MoveTo(x, Rect.Top);
LineTo(x, Rect.Bottom);
Dec(i);
until (i<0)
end;
end;
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107086.html原文链接:https://javaforall.net