Delphi实现凭证格式的DBGrid

//写一个玩玩~~ procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var I, J, T: Integer; C: Char; S: string; vRect: TRect; const cCnNumber: array['0'..'9'] of string = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); begin if not Odd(TDBGrid(Sender).DataSource.DataSet.RecNo) then begin TDBGrid(Sender).Canvas.Brush.Color := $cfcfff; TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State); end; if not SameText(Column.FieldName, 'Salary') then Exit; if not Assigned(Column.Field) then Exit; ///////Begin 处理成全角数字 S := Format('%.2f', [Column.Field.AsFloat]); for I := Length(S) downto 1 do begin C := S[I]; if C = '.' then Delete(S, I, 1) else begin Delete(S, I, 1); Insert(cCnNumber[C], S, I); end; end; S := '¥' + S; ///////End 处理成全角数字 with TDBGrid(Sender).Canvas do begin ///////Begin 写文字 vRect := Rect; FillRect(Rect); vRect.Right := vRect.Right - 4; vRect.Top := vRect.Top + 2; DrawText(Handle, PChar(S), Length(S), vRect, DT_RIGHT or DT_VCENTER); ///////End 写文字 ///////Begin 画线条 J := Rect.Right - Rect.Left; //计算宽度 T := TextWidth('0'); I := 1; while I * T + T div 2 < J do begin if I = 2 then Pen.Color := clRed else begin if (I > 3) and ((I - 2) mod 3 = 0) then Pen.Color := clBlue else Pen.Color := clGreen; end; MoveTo(Rect.Right - I * T - T div 2, Rect.Top); LineTo(Rect.Right - I * T - T div 2, Rect.Bottom); Inc(I); end; ///////End 画线条 end; end;

你可能感兴趣的:(String,Integer,delete,insert,div,Delphi)