Navigation: TextEd > Extension and Scripts > Dialogs >

TPrintDialog

 

 

 

TPrintDialog displays a Print dialog.


The TPrintDialog component displays a standard Windows dialog box for sending jobs to a printer. The dialog is modal and does not appear at runtime until it is activated by a call to the Execute method.


 


Properties and methods



 

constructor Create(TComponent AOwner);

Creates and initializes a print dialog.

 

Ex.

TPrintDialog printDlg = TPrintDialog.Create(form);


 

function bool Execute;

Execute opens the Print dialog, returning true when the user clicks Print and false when the user clicks Cancel.

 

Ex.

TPrintDialog printDlg = TPrintDialog.Create(form);

if (printDlg.Execute) {

   // Do some printing

 

}

printDlg.Free;


 

procedure Free;

Destroys an object and frees its associated memory, if necessary.


 

property bool Collate;

Indicates whether the Collate check box is selected. Collate is true whenever the Collate check box is selected in the Print dialog. To make the dialog open with the check box selected, set Collate to true.


 

property int Copies;

Indicates the number copies selected in the Print dialog. If Copies is 0 or 1, the dialog will have 1 in the Number of Copies field. To make the dialog open with 2 or more copies selected, set the value of Copies.


 

property int FromPage;

Indicates the page on which the print job is to begin. The FromPage property corresponds to the From field in the Print dialog.


 

property int ToPage;

Indicates the page on which the print job is to end. The ToPage property corresponds to the To field in the Print dialog.


 

property TPrintRange PrintRange;

Indicates the type of print range selected in the dialog. The value of PrintRange corresponds the All, Selection, and Pages (From/To) radio buttons in the Print dialog.


enum TPrintRange {

  prAllPages,

  prSelection,

  prPageNums

};


Ex.

printDlg.PrintRange = prAllPages;


 


Usage



 

TForm f;
TButton btnPrint;
TMemo memo;
 
/////////////////////////////////////
// Open a print dialog and print
// the memo text.
/////////////////////////////////////
void btnPrintClick(TObject Sender) {
   TPrintDialog printDlg = TPrintDialog.Create(f);
   if (printDlg.Execute) {
      int line = 0;
      Printer.BeginDoc;
      Printer.Canvas.Font = memo.Font;
      for (int i = 0; i < memo.Lines.Count - 1; i++) {
         Printer.Canvas.TextOut(0, line, memo.Lines[i]);
         line = line + (-Printer.Canvas.Font.Height);
         if (line >= Printer.PageHeight) {
           Printer.NewPage;
         }
      }
      Printer.EndDoc;
   }
   printDlg.Free;
}
 
// Main procedure
{
   // Create a new window (form)
   f = new TForm(nil);
   f.Caption = "Print memo text";
   f.Position = poScreenCenter;
   f.Width = 400;
   f.Height = 300;
   
   // Add a button to the window
   btnPrint = new TButton(f);
   btnPrint.Name = "btnPrint";
   btnPrint.Parent = f;
   btnPrint.SetBounds(10, 20, 75, 25);
   btnPrint.Anchors = akLeft+akTop;
   btnPrint.Caption = "Print...";
   btnPrint.OnClick = &btnPrintClick;
 
   // Add a text edit control (memo) to the window
   memo = new TMemo(f);
   memo.Name = "memoLorem";
   memo.Parent = f;
   memo.SetBounds(10, 50, 360, 200);
   memo.Anchors = akLeft+akTop;
   memo.Lines.Text = "Lorem Ipsum iaculis audire mi moderatius\r\ncorpora dictumst turpis."; 
   
   // Show the window
   f.ShowModal;
   f.Free;
}


 


 


 

 

 

 

 

Copyright © 2022 Rickard Johansson