xtrareports-devexpress-dot-xtrareports-dot-ui-dot-xrcontrol-817bb43e.md
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
public virtual event DrawEventHandler Draw
Public Overridable Event Draw As DrawEventHandler
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. |
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.
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);
}
}
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