Back to Devexpress

XRControl.Draw Event

xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-817bb43e.md

latest4.4 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public virtual event DrawEventHandler Draw
vb
Public Overridable Event Draw As DrawEventHandler

Event Data

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

PropertyDescription
BoundsGets a rectangle object specifying the height, width and location of the control.
BrickGets a visual brick that represents this control’s contents on a report page.
UniGraphicsProvides access to an object that is used to draw report components.

The event data class exposes the following methods:

MethodDescription
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.

csharp
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);
    }
}
vb
Imports System.Drawing
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...

Private Sub XrControl1_Draw(ByVal sender As Object, ByVal e As DrawEventArgs) _
Handles XrControl1.Draw
    ' Get a rectangle occupied by a control.
    Dim rect As Rectangle = Rectangle.Truncate(e.Bounds)

    If TypeOf e.UniGraphics Is GdiGraphics Then
        ' Obtain a Graphics object.
        Dim graph = CType(e.UniGraphics, GdiGraphics)

        ' Fill the interior of the ellipse defined
        ' by the rectangle with a Red color.
        graph.Graphics.FillEllipse(Brushes.Red, rect)
    End If
End Sub

See Also

XRControl Class

XRControl Members

DevExpress.XtraReports.UI Namespace