Back to Devexpress

PrintOnPageEventArgs.PageCount Property

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-printonpageeventargs.md

latest3.4 KB
Original Source

PrintOnPageEventArgs.PageCount Property

Gets the number of all pages presented in the created report.

Namespace : DevExpress.XtraReports.UI

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public int PageCount { get; }
vb
Public ReadOnly Property PageCount As Integer

Property Value

TypeDescription
Int32

An integer value which represents the number of all pages in a report.

|

Remarks

Use the PageCount property to obtain information on the number of pages presented in the created document. Note that this number isn’t defined when the XRControl.BeforePrint event is called. So, to be able to obtain the number of all report pages, you need to handle the XRControl.PrintOnPage event.

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.

csharp
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;
}
vb
Imports DevExpress.XtraReports.UI
' ...

Private Sub OnLabelPrintOnPage(ByVal sender As Object, ByVal e As PrintOnPageEventArgs) _
Handles xrLabel1.PrintOnPage
    ' Check if the label is printed on the last page.
    If e.PageIndex = e.PageCount - 1 Then
        ' Set its text.
        CType(sender, XRLabel).Text = "The last page!"
    Else
        ' Check if the label is printed on the odd page.
        If e.PageIndex Mod 2 = 0 Then
            ' Cancel its printing.
            e.Cancel = True
        End If
    End If
End Sub

See Also

PageIndex

PrintOnPageEventArgs Class

PrintOnPageEventArgs Members

DevExpress.XtraReports.UI Namespace