unit MainUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Printers, ComCtrls, ExtCtrls, RxGIF;

type
  TForm1 = class(TForm)
    Button1: TButton;
    PrintDialog1: TPrintDialog;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 i, Start, Stop: Integer;
begin
 PrintDialog1.Options := [poPageNums, poSelection];
 PrintDialog1.FromPage := 1;
 PrintDialog1.ToPage := PageControl1.PageCount;
 PrintDialog1.MinPage := 1;
 PrintDialog1.MaxPage := PageControl1.PageCount;
 if not PrintDialog1.Execute then exit;

 if PrintDialog1.PrintRange = prAllPages then
  begin
   Start := PrintDialog1.MinPage - 1;
   Stop := PrintDialog1.MaxPage - 1;
  end
 else
  if PrintDialog1.PrintRange = prSelection then
   begin
    Start := PageControl1.ActivePageIndex;
    Stop := Start;
   end
  else
   begin
    Start := PrintDialog1.FromPage - 1;
    Stop := PrintDialog1.ToPage - 1;
   end;

 Printer.BeginDoc;
 for i := Start to Stop do
  begin
   PageControl1.Pages[i].PaintTo(Printer.Handle, 10, 10);
   if i <> Stop then
    Printer.NewPage;
  end;
 Printer.EndDoc;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Close;
end;

end.
