Skip to main content

XRControl.BeforePrint Event

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

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public virtual event BeforePrintEventHandler BeforePrint

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:

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.

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;
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeforePrint event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also