Printing Multiple Controls

Printing a document is quite straightforward. The ViewMode property is set to 4 - Simple Control, so the controls are printed like they are formatted on the screen. The PageMargin properties are used to specify the positions of the controls on the page.

procedure TForm1.Print1Click(Sender: TObject);
begin
   Printer.BeginDoc;
   For i := 1 To MaxID do begin
      TXhWnd := FindComponent('TXTextControl' +
            InttoStr(i));
      TTXTextControl(TXhWnd).PrintDevice := Printer.Handle;
      TTXTextControl(TXhWnd).PageMarginL :=
            toTwip(TTXTextControl(TXhWnd).Left);
      TTXTextControl(TXhWnd).PageMarginT :=
            toTwip(TTXTextControl(TXhWnd).Top);
      TTXTextControl(TXhWnd).PrintPage (1);
   end;
   Printer.NewPage;
   Printer.EndDoc;
end;

The complete source code of the Forms1 sample program is contained in the Samples\Delphi\Forms1 sample source directory.