这个示例展示了如何在打印控件时获取当前页码。
在 XRControl.PrintOnPage 事件中,PrintOnPageEventArgs.PageCount 和 PrintOnPageEventArgs.PageIndex 属性允许获取页面的 当前页码 和 总页数 (PrintOnPageEventArgs.PageIndex 属性返回从零开始的索引)。
注意,XRControl.PrintOnPage 事件的触发顺序在 XRControl.BeforePrint 和 XRControl.AfterPrint 事件的后面。
| C# |  复制代码 | 
|---|---|
using System; using System.Windows.Forms; 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; } } }  | |
| Visual Basic |  复制代码 | 
|---|---|
Imports System Imports System.Windows.Forms Imports DevExpress.XtraReports.UI ' ... Private Sub xrLabel1_PrintOnPage(ByVal sender As Object, _ ByVal e As PrintOnPageEventArgs) Handles xrLabel1.PrintOnPage If e.PageCount > 0 Then ' Check if the control is printed on the first page. If e.PageIndex = 0 Then ' Cancels the control's printing. e.Cancel = True End If End If End Sub  | |
 Show Me  | 
|---|
在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E1952。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。  | 
  
  
  
  
  
  
  
Show Me 