XRControl.BeforePrint Event
Occurs before an XRControl object creates its image in a report being generated.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v23.1.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Event Data
The BeforePrint event's data class is CancelEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cancel | Gets or sets a value indicating whether the event should be canceled. |
Remarks
The BeforePrint event occurs when the report’s CreateDocument method is called (internally form other methods or explicitly).
You can handle this event to change the control’s properties. The event argument’s Cancel property allows you to cancel control rendering.
Note
This event does not have any relation to the actual printing process. To manage print settings, handle the PrintingSystemBase.StartPrint event instead.
The BeforePrint is not raised when you export the document to any available format because the export operation does not recreate the report document.
The BeforePrint event is raised with other events in the following order:
- BeforePrint
- XRControl.AfterPrint
- XRControl.PrintOnPage
See Report Events for more information.
Example
This example demonstrates how to handle a label’s XRControl.BeforePrint
event, how to access an XRLabel object in this event handler, and how to customize its appearance based on a specific condition.
Tip
Online Example: How to change a label’s appearance in its BeforePrint event handler
using System;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
// ...
private void xrLabel_BeforePrint(object sender, CancelEventArgs e) {
// Obtain the current label.
XRLabel label = (XRLabel)sender;
// Get the total value.
double total = Convert.ToDouble(GetCurrentColumnValue("Total"));
// Customize the label's appearance.
if (total < 100) {
label.ForeColor = Color.White;
label.BackColor = Color.Red;
}
else if (total > 1000) {
label.ForeColor = Color.White;
label.BackColor = Color.Green;
}
else {
label.ForeColor = Color.Black;
label.BackColor = Color.Transparent;
}
}