Skip to main content

DevExpress v24.1 Update — Your Feedback Matters

Our What's New in v24.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

XRControl.Draw Event

Occurs when an XRControl object is drawn or redrawn in a report’s Print Preview.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v24.1.dll

NuGet Package: DevExpress.Reporting.Core

#Declaration

public virtual event DrawEventHandler Draw

#Event Data

The Draw event's data class is DrawEventArgs. The following properties provide information specific to this event:

Property Description
Bounds Gets a rectangle object specifying the height, width and location of the control.
Brick Gets a visual brick that represents this control’s contents on a report page.
UniGraphics Provides access to an object that is used to draw report components.

The event data class exposes the following methods:

Method Description
GetPageVisualBricksEnumerator() For internal use. Returns an enumerator containing visual bricks generated for all report controls on this page.

#Remarks

Note that although the Draw event can be useful in many cases, when it is necessary to create a customized view of a control, we do not recommend using it. The reason is that customization, which is done in the Draw event’s handler, can’t be correctly exported to different formats (e.g. HTML, MHT, RTF, etc.). The better approach is to create a custom report control, which is correctly printed and exported because it consists of Printing System bricks. To learn more on how to create a custom report control, refer to the Creating a Custom Progress Bar Control tutorial in this documentation.

#Example

The following example demonstrates how to use the XRControl.Draw event. The handler method below draws a red ellipse in the rectangle occupied by the XRControl object.

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

private void xrControl1_Draw(object sender, DrawEventArgs e) {
    // Get a rectangle occupied by a control.
    Rectangle rect = Rectangle.Truncate(e.Bounds);

    if(e.UniGraphics is GdiGraphics) {
        // Obtain a Graphics object.
        GdiGraphics graph = (GdiGraphics)e.UniGraphics;

        // Fill the interior of the ellipse defined
        // by the rectangle with a Red color.
        graph.Graphics.FillEllipse(Brushes.Red, rect);
    }
}
See Also