Skip to main content

XRControl.PrintOnPage Event

Occurs when the representation of a control is printed on the current page of the report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public virtual event PrintOnPageEventHandler PrintOnPage

Event Data

The PrintOnPage event's data class is PrintOnPageEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
PageCount Gets the number of all pages presented in the created report.
PageIndex Gets the index of the current page which the control will be printed on.

Remarks

Use this event to perform actions when a control is printed on a particular page in a report. The current page index can be accessed via the PrintOnPageEventArgs.PageIndex property. The PrintOnPageEventArgs.PageCount property is also available, since the event is raised for the current control after all the document pages are created.

When using the CachedReportSource component to generate a report document, the PrintOnPage event is raised each time a page with the current control is created. In this connection, the total number of pages is unknown at the moment the event fires and you cannot use the PrintOnPageEventArgs.PageCount property in the event handler.

Note

Note, however, that changing a control’s contents at this event will not change a report’s layout (locations and sizes of bricks in a final document), since the report document is already created at this time.

The PrintOnPage event is raised along with the other associated events which are listed below in the order that they are raised:

To learn more, see Report Events.

Example

The following example demonstrates how to use the XRControl.PrintOnPage event. The event handler below checks if an xrLabel1 is being printed on the last page (in case the PrintOnPageEventArgs.PageCount property is equal to PrintOnPageEventArgs.PageIndex minus 1), and, if yes, sets its text to “The last page!”. Otherwise, it checks if a label is being printed on the odd page, and, if yes, it cancels its printing.

using DevExpress.XtraReports.UI;
// ...

private void xrLabel1_PrintOnPage(object sender, PrintOnPageEventArgs e) {
    // Check if the label is printed on the last page.
    // Note that the PageCount property value is not valid if you
    // use the CachedReportSource component to generate a report document
    if (e.PageIndex == e.PageCount-1)
        // Set its text.
        ((XRLabel)sender).Text = "The last page!";
    else
        // Check if the label is printed on the odd page.
        if (e.PageIndex % 2 == 0)
            // Cancel its printing.
            e.Cancel = true;
}
See Also