Back to Devexpress

CustomDrawEventArgs.DefaultDraw() Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-customdraweventargs-960b712f.md

latest5.8 KB
Original Source

CustomDrawEventArgs.DefaultDraw() Method

Performs default painting of an element.

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
public void DefaultDraw()
vb
Public Sub DefaultDraw

Remarks

The DefaultDraw method can be useful if you need to draw custom information over the default element rendering. To do this, call the DefaultDraw method and then draw custom information using the methods provided by the CustomDrawEventArgs.Graphics object.

The DefaultDraw method automatically sets the CustomDrawEventArgs.Handled property to true to prevent additional default painting from being performed after a custom draw event handler has been completed.

The DefaultDraw method does nothing if the CustomDrawEventArgs.Handled property has already been set to true.

Example

In the sample below, the GridView.CustomDrawCell event is handled to custom-paint data cells.

The CustomDrawEventArgs.DefaultDraw method applies the default draw to all cells. For all “Units in Stock” cells that display 0 , a custom icon is drawn on top of this default cell rendering.

csharp
Image warningImage = Image.FromFile("c:\\warning.png");

private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
    if (e.Column.FieldName == "UnitsInStock") {
        e.DefaultDraw();
        if (Convert.ToInt32(e.CellValue) == 0)
            e.Cache.DrawImage(warningImage, e.Bounds.Location);
    }
}
vb
Dim warningImage As Image = Image.FromFile("c:\warningImage.png")

Private Sub GridView1_CustomDrawCell(sender As Object, e As RowCellCustomDrawEventArgs) Handles GridView1.CustomDrawCell
    If e.Column.FieldName = "UnitsInStock" Then
        e.DefaultDraw()
        If Convert.ToInt32(e.CellValue) = 0 Then
            e.Cache.DrawImage(warningImage, e.Bounds.Location)
        End If
    End If
End Sub

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

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.

winforms-grid-draw-thick-border-abound-focused-cell/CS/Form1.cs#L17

csharp
if (e.Column == view.FocusedColumn && e.RowHandle == view.FocusedRowHandle) {
    e.DefaultDraw();
    CellDrawHelper.DrawCellBorder(e);

winforms-grid-display-icons-in-data-cells/CS/Form1.cs#L245

csharp
e.DisplayText = string.Empty;
e.DefaultDraw();
e.Cache.DrawImage(GetImageFromResource(e.CellValue.ToString()), e.Bounds.X, e.Bounds.Y);

winforms-grid-display-colored-progress-bars/CS/ColoredProgressBar/CustomPaintedProgressBarHelper.cs#L18

csharp
DrawProgressBar(e);
e.DefaultDraw();
e.Handled = true;

winforms-grid-draw-thick-border-abound-focused-cell/VB/Form1.vb#L22

vb
If e.Column Is view.FocusedColumn AndAlso e.RowHandle = view.FocusedRowHandle Then
    e.DefaultDraw()
    DrawCellBorder(e)

winforms-grid-display-icons-in-data-cells/VB/Form1.vb#L217

vb
e.DisplayText = String.Empty
e.DefaultDraw()
e.Cache.DrawImage(GetImageFromResource(e.CellValue.ToString()), e.Bounds.X, e.Bounds.Y)

winforms-grid-display-colored-progress-bars/VB/ColoredProgressBar/CustomPaintedProgressBarHelper.vb#L23

vb
DrawProgressBar(e)
e.DefaultDraw()
e.Handled = True

See Also

CustomDrawEventArgs Class

CustomDrawEventArgs Members

DevExpress.XtraGrid.Views.Base Namespace