procedure TFrmDTWater.PrintGrid (GenStrGrid: TStringGrid; sTitle: String); const LeftBlank = 1; // define the margins, in centimeters RightBlank = 1; TopBlank = 2; BottomBlank = 2; var PointX, PointY: integer; PointScale, PrintStep : Integer; S1, S2, S3: String; x, y: integer; i, k: integer; begin // horizontal print Printer.orientation: = poporTrait; if printDialog1.execute1 begin // Get the current printer resolution Pointx : = Trunc (Printer.Handle, Logpixelsx) / 2.54); Pointy: = Trunc (GetDeviceCaps (Printer.Handle, Logpixelsy) / 2.54);
/ / Calculate the proportion of switches from the screen to the printer according to the resolution of the printer and the screen Pointscale: = trunc (Printer.Handle, Logpixelsx) /screen.pixelsperinch 0.5);
// Print font and size printer.canvas.font.name:= 'Song body'; printer.canvas.font.size: = 16; printer.canvas.font.style = [fsbold];
/ / Determine the height of each row according to the size of the font to = TTL; Printstep: = Printer.canvas.TextHeight (S1) 16;
// Print start point position x: = pointx * leftblank; y: = power * topblank;
Printer.begindoc; // Print Title x: = x stringgrid1.defaultColWidth * PointScale * 2; Printer.canvas.Textout (x 8, y 8, s1); y: = y printstep; // Print date Printer .Canvas.font.name: = 'Song body'; printer.canvas.font.size: = 12; printer.canvas.font.style: = []; // Determine the height of each row according to the size of the font: = formattime ('YYYY-MM-DD', DATE ()); Printstep: = Printer.canvas.TextHeight (S2) 20; x: = x stringgrid1.defaultColwidth * PointScale * 3; Printer.canvas.Textout (x 8 , y 8, s2); x: = pointx * leftblank; y: = y printstep; print data K: = 0; While K <= stringgrid1.rowcount do begin // Print all columns for i: = 0 To stringgrid1.colcount-1 do begin
/ / If the column to be printed is exceeded, the column IF (X StringGrid1.defaultColWidth * Pointscale) <= (Printer.PageWidth-Pointx * RightBlank) THEN BEGIN / / Picture Table Ling // One line printhead IF k = 1 kilnvas.font.style = [fsbold] else printer.canvas.font.style: = []; if k <> 0 Then Printer.canvas.Rectangle (x, y) X stringgrid1.defaultColwidth * PointScale 200, y printstep); if K <> 0 Then Printer.canvas.textout (x 8, y 8, stringgrid1.cells [i, k]);
/ / Calculate the abscissa X: = x stringgrid1.defaultColWidth * PointScale 200; end; {if not (y = pointy * Topblank) THEN K: = K 1;} x: = pointx * leftblank; y : = y printstep; // Distribution IF (Y Print-Pointy * Bottomblank) THEN BEGINTER.NEWPAGE; Y: = Pointy * Topblank; End; k: = k 1; // Print the end font and size printer.canvas.font.name:= 'Song body'; printer.canvas.font.size: = 15; Printer.canvas.Font.Style := [fsbold]; S2: = 'Title' ; X: = x stringgrid1.defaultColwidth * PointScale * 3; Printer.canvas.TextOut (x 8, y 8, s2); printer.enddoc; showMessage ('Start printing ...'); statusbar1.panels. Items [0] .Text: = 'is printing ...'; //timer1.enabled:=true; end;