PrinterPageWidth (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires a button and a memo on a form. When you click the button, the content of the memo is printed, with a 200-pixel border around the page. To run this example successfully, include <Printers.hpp> in your unit file. Note: The TMemo wraps the lines of the text files, so, in order to see the TextRect clip, the memo width must be large and the lines in the text file must be long.

Code

uses Printers;

procedure TForm1.Button1Click(Sender: TObject);
var
  X, Y, I, margin: Integer;
begin
  with Printer do
  begin
    BeginDoc;
    margin := 1000;
    X := margin;
    Y := margin;
    I := 0;
    while(Y < PageHeight) do
    begin
      Canvas.TextRect(Rect(X, Y, PageWidth-margin, PageHeight-margin),
                    X, Y, Memo1.Lines[I]);
      Y := Y + 100;
      I := I + 1;
    end;
    EndDoc;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Width := 1000;
  Memo1.Lines.LoadFromFile('readme.txt');
end;

Uses