The Print and PrintSetUp Dialogues

The Print Dialog opens the print dialog box and allows the standard settings to be chosen, including choice of printer, paper orientation, and so on.

The example begun in the ColorDialog section is extended by adding a Print dialog and a PrinterSetUpDialog.

The code for the Print button (second from left)

procedure TForm1.ToolButton2Click(Sender: TObject);
var i:integer;
begin
 if PrintDialog1.Execute then
 with Printer do
 begin
  BeginDoc;
  for i:=0 to RichEdit1.Lines.Count do
  Canvas.TextOut(200,200 + (i * Canvas.TextHeight(RichEdit1.Lines.Strings[i])),
  RichEdit1.Lines.Strings[i]);
  Refresh;
  EndDoc;
 end;
end;

This code is explained in more detail in the section on printing.

The code for the PrintSetUp button (on the right):

procedure TForm1.ToolButton3Click(Sender: TObject);
begin
 printersetupdialog1.Execute;
end;

That's all that's needed!

Back to Palette List