XRControl.BeforePrint Event

Occurs before an XRControl object creates its image in a report being previewed/printed/exported.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public virtual event PrintEventHandler BeforePrint
Public Overridable Event BeforePrint As PrintEventHandler

The event handler PrintEventHandler receives an argument of the PrintEventArgs type.

This event can be used to change the properties of an XRControl object programmatically.

You can use the Cancel property to cancel the printing of an XRControl object.

The BeforePrint event is raised along with the other events listed below in the following order:

To learn more, see Report Events.

Examples

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.

using System;
using System.Drawing;
using DevExpress.XtraReports.UI;
// ...

private void xrLabel_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs 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;
    }
}

See Also