1. Computing

Changing the Title of a Print Dialog in Delphi

Specifing TPrintDialog's Caption

From , former About.com Guide

tprintdialog custom title

tprintdialog custom title

The components on the "Dialogs" page of the Tool / Component Palette make the Windows standard dialog boxes available to your applications. The dialog boxes provide a consistent interface for file operations such as opening, saving, and printing files.

TOpenDialog, TSaveDialog and others inherit from TCommonDialog. Most dialogs expose the Title property you can use to specify the title / caption in the dialog’s title bar.

TPrintDialog.Title

The TPrintDialog component displays a standard Windows dialog box for sending jobs to a printer.

Unfortunately, the TPrintDialog does not expose the Title property.

By handing the OnShow event of a print dialog you can specify the text for the dialog’s title bar:

 //handles PrintDialog1.OnShow
 procedure TReportForm.PrintDialog1Show(Sender: TObject) ;
 begin
   if Sender is TPrintDialog then
     SetWindowText(
       TPrintDialog(Sender).Handle,
       'How do you want to print your report?') ;
 end;
 
Note: a common dialog box opens when its Execute method is called.

Delphi tips navigator:
» Delayed Event Handling Using Event Handler Detaching
« Generic Solution to Freeing Objects in Delphi's TStringList Collections

©2013 About.com. All rights reserved.