Skip to main content

Step 1 — Control Printing Basics

  • 3 minutes to read

This topic contains basic information on VCL control printing capabilities using the standard TListBox component as an example.

Tip

The core print-related APIs are designed for simple document generation scenarios and print/content export operations available for the majority of DevExpress VCL Controls (shipped as part of ExpressQuantum Pack, VCL Subscription, and VCL Subscription+).

For most advanced report generation and BI/data analytics usage scenarios, we recommend that you use our ExpressReports and ExpressDashboards Suites (available as part of the VCL Subscription +). These advanced solutions include both the powerful report generator and customizable print preview, BI dashboard designer and viewer for data analytics (available both at design- and runtime), smart/AI functions, non-GUI/service-based document generation, and much more.

VCL Printing System: A Print Preview Example for the Standard VCL List Box

Create & Configure a RAD Studio Project

Create a new Delphi or C++Builder project and place the TdxComponentPrinter component on a form.

VCL Printing System: Add a Component Printer

Add a TListBox component and select it. Click the button for the Items property in the Object Inspector to display the collection editor dialog. Create five items as demonstrated in the following image and click the OK button to confirm the changes.

VCL Printing System: Add and Configure a List Box Component

Configure the Component Printer

Right-click the TdxComponentPrinter component and choose ReportLinks… from the context menu to display the print link collection editor.

VCL Printing System: Display the "Print Link" Collection Editor

Click the Add… button to display the Add Report dialog. Select the list box control from the list of available sources and click the OK button to create a print link for the list box.

VCL Printing System: Select the List Box and Create a Print Link

Tip

You can rename the print link component using the Name field within the Add Report dialog.

Close the collection editor.

Display the Print Preview Dialog at Runtime

Add a TcxButton component on a form and change the button’s caption to Print the ListBox. Handle the button’s OnClick event handler as follows to display the Print Preview dialog for the TListBox component at runtime:

uses
  dxPSCore,    // Declares the TdxComponentPrinter component and related types
  dxPSLbxLnk,  // Declares the TdxListBoxReportLink component
  cxButtons;   // Declares the TcxButton component
// ...

procedure TMyForm.cxPrintButtonClick(Sender: TObject);
begin
  dxComponentPrinter1.Preview(True, dxListBoxReportLink1);
end;

Run & Test the App

Run the application and click the Print the ListBox button to display the Print Preview dialog.

VCL Printing System: A Print Preview Example for the Standard VCL List Box

You can save TListBox control content to a file using the File | Save… menu option.

VCL Printing System: The Content Export ("Save") Option

The Save As dialog allows you to select the target folder and specify the required file name. You can load a previously saved print document using the Load… menu item. The Unload option allows you to restore previously displayed document after a load operation.

To print control content without user interaction, you can call the following TdxComponentPrinter methods:

TCustomdxComponentPrinter.Print
Prints a report on the default printer.
TCustomdxComponentPrinter.PrintEx
Prints report pages.
TCustomdxComponentPrinter.Preview
Activates the Print Preview dialog.

Tip

Refer to the TdxComponentPrinter class description for detailed information (including code examples) on all available options.

Next Step

The next step demonstrates print layout and appearance customization using the built-in UI.