画DBGRID,DBGRIDEH中文帐簿金额栏

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://www.cnblogs.com/hnxxcxg/archive/2009/12/20/2940745.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值