Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

Tip

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;
        }
    }
}

Tip

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.