Skip to main content
A newer version of this page is available. .

Obtain the Current Page Number when Printing a Control

This example demonstrates how to obtain the number of the page that is currently printing.

You can obtain both the current and total number of document pages using the PrintOnPageEventArgs.PageCount and PrintOnPageEventArgs.PageIndex properties in the XRControl.PrintOnPage event handler. The PrintOnPageEventArgs.PageIndex property indicates the zero-based page index.


The XRControl.PrintOnPage event is raised after both the XRControl.BeforePrint and XRControl.AfterPrint events. See Report Events for more information.

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

private void xrLabel1_PrintOnPage(object sender, PrintOnPageEventArgs e) {
    if (e.PageCount > 0) {
        // Check if the control is printed on the first page.
        if (e.PageIndex == 0) {
            // Cancels the control's printing.
            e.Cancel = true;


You need to handle the corresponding script event to serialize your custom logic with the report’s definition and maintain it in end-user applications.

Consider using the XRPageInfo control for displaying page numbers in a report.