The requested page is not available for the requested platform. You are viewing the content for Default platform.

XRControl.BeforePrint Event

Occurs before an XRControl object creates its image in a report being generated.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v19.2.dll

Declaration

public virtual event PrintEventHandler BeforePrint
Public Overridable Event BeforePrint As PrintEventHandler

Event Data

The BeforePrint event handler receives an argument of the PrintEventArgs type. The following properties provide information specific to this event.

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled.
(Inherited from CancelEventArgs)
PrintAction Returns PrintToFile in all cases.

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:

See Report Events for more information.

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