Step 1 – Control Printing Basics
- 3 minutes to read
This topic will show you the minimum steps required to print a control. Later topics in this Quick Start guide will consider some printing capabilities in more detail. For this example a list box control will be used.
Follow the steps below:
Create a new application.
Drag the TdxComponentPrinter component onto the form.
- Drag a list box control onto the form. Select the control to display its properties within the Object Inspector window. Click the button located at the right of Items property (which corresponds to items), this will invoke the items collection editor. Add items as shown in the image below and then click the OK button to close the dialog and save your changes.
- Right-click the TdxComponentPrinter component and choose the ReportLinks… item from the context menu, which will then invoke the report links collection editor.
- Click the Add… button, from the invoked dialog to choose the list box control and then click the OK button. This will add a report link to the component printer, which will later be used to print the list box control.
Note that a custom name has been entered into the dialog’s Name field. That name will be used to refer to the report link directly in code.
- Close the report links collection editor. Drag a button control onto the form and change its caption to ‘Print the ListBox‘. Then write the following code for the button’s OnClick event handler.
procedure TForm1.Button1Click(Sender: TObject);
begin
dxComponentPrinter1.Preview(True, listBoxReportLink);
end;
This code will invoke the print preview window so that end-users are able to customize the printer page settings and then print the list box control.
- Run the application. Click the “Print the ListBox” button to invoke the print preview dialog.
By default, the Print Preview dialog style is Standard (or Ribbon if the ExpressBars Suite is installed – see the TdxPSEngineController.PreviewDialogStyle property for more information).
To save a report as a file open the File menu and click Save… (see also the TBasedxReportLink.SaveDataToFile and TBasedxReportLink.SaveDataToStream methods).
The file dialog will appear. Select the folder in which to save the file and type in a name for it. To load a report saved as a file into the preview window choose the Load… menu item (see also the TBasedxReportLink.LoadDataFromFile and TBasedxReportLink.LoadDataFromStream methods). If after a saved report has been loaded into the preview window you need to restore the report that was displayed prior to the current report being loaded use the Unload menu item.
Note
You may need to print a component directly (without displaying the print preview window first). To accomplish this, call the component printer’s Print or PrintEx method instead of the Preview method.
The next step demonstrates how to customize the appearance of printed reports using the built-in UI.