简体   繁体   English

如何在页面中心打印字符串网格?

[英]How to print a string grid in the center of a page?

So I want to print a string grid in the middle/center of another printed page that already has a printed/header and footer, but I'm not sure how to print the string grid in the middle/center of the page?所以我想在另一个已经有打印/页眉和页脚的打印页面的中间/中心打印一个字符串网格,但是我不确定如何在页面的中间/中心打印字符串网格? Is there anything in the code below that I can change to do that?下面的代码中有什么我可以更改的吗? Or do I have to do something else completely?还是我必须完全做其他事情?

Thanks in advance for all the help!提前感谢所有帮助!

Example of the type of page I have to print on (In the open part of the page):我必须打印的页面类型示例(在页面的打开部分): 在此处输入图像描述

Code I've used for one of the other buttons that also prints:我用于也打印的其他按钮之一的代码:

procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
var
  X1, X2: Integer;
  Y1, Y2: Integer;
  TmpI: Integer;
  F: Integer;
  TR: TRect;
begin
  Printer.Title := sTitle;
  Printer.BeginDoc;
  Printer.Canvas.Pen.Color  := 0;
  Printer.Canvas.Font.Name  := 'Times New Roman';
  Printer.Canvas.Font.Size  := 12;
  Printer.Canvas.Font.Style := [fsBold, fsUnderline];
  Printer.Canvas.TextOut(0, 100, Printer.Title);
  for F := 1 to sGrid.ColCount - 1 do 
  begin
    X1 := 0;
    for TmpI := 1 to (F - 1) do
      X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
    Y1 := 300;
    X2 := 0;
    for TmpI := 1 to F do
      X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
    Y2 := 450;
    TR := Rect(X1, Y1, X2 - 30, Y2);
    Printer.Canvas.Font.Style := [fsBold];
    Printer.Canvas.Font.Size := 7;
    Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
    Printer.Canvas.Font.Style := [];
    for TmpI := 1 to sGrid.RowCount - 1 do 
    begin
      Y1 := 150 * TmpI + 300;
      Y2 := 150 * (TmpI + 1) + 300;
      TR := Rect(X1, Y1, X2 - 30, Y2);
      Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
    end;
  end;
  Printer.EndDoc;
end;

Kind Regards PrimeBeat亲切的问候 PrimeBeat

You can get printer width and height in pixel ( Printer.PageWidth and Printer.PageHeight ).您可以获得以像素为单位的打印机宽度和高度( Printer.PageWidthPrinter.PageHeight )。 You can get text with and height using Printer.Canvas.TextExtent .您可以使用Printer.Canvas.TextExtent获取文本和高度。 You have your grid so you know the number of rows and column.你有你的网格,所以你知道行数和列数。 The rest is some easy computing. rest 是一些简单的计算。 You can adapt the font size so that the grid fits in the given space.您可以调整字体大小,使网格适合给定的空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM