Back to Devexpress

CustomDrawObjectEventsArgs.Handled Property

windowsforms-devexpress-dot-xtraspreadsheet-dot-customdrawobjecteventsargs.md

latest5.0 KB
Original Source

CustomDrawObjectEventsArgs.Handled Property

Gets or sets whether an event is handled. If true, the default actions are not required.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public bool Handled { get; set; }
vb
Public Property Handled As Boolean

Property Value

TypeDescription
Boolean

true if default painting isn’t required; otherwise, false.

|

Remarks

The events used to custom paint the SpreadsheetControl’s elements fire before these elements are painted in their default manner. If the event parameter’s Handled property is set to true , default painting is not performed. Otherwise, the SpreadsheetControl’s standard drawing mechanism overrides any custom painting.

You can call the CustomDrawObjectEventsArgs.DrawDefault method in the event handler to use the default drawing mechanism to render an element, and then set Handled to true to paint custom drawing over default graphics.

The code example below shows how to use the CustomDrawCellBackground event to draw a custom shape over default rendering for cells that contain 0 in the “Units In Stock” column.

csharp
spreadsheetControl1.CustomDrawCellBackground += (s, e) =>
{
    if (e.Cell.ColumnIndex == 2 && e.Cell.Value == 0)
    {
        int size = 10;
        e.BackColor = Color.LightPink;
        e.DrawDefault();
        e.Handled = true;
        e.Cache.FillEllipse(Color.Red, new Rectangle(e.Bounds.Left + size, e.Bounds.Top + size / 2, size, size));
    }
};
vb
AddHandler spreadsheetControl1.CustomDrawCellBackground,
    Sub(s, e)
        If e.Cell.ColumnIndex = 2 AndAlso e.Cell.Value = 0 Then
            Dim size As Integer = 10
            e.DrawDefault()
            e.Handled = True
            e.Cache.FillEllipse(Color.Red, New Rectangle(e.Bounds.Left + size, e.Bounds.Top + size \ 2, size, size))
        End If
    End Sub

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

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-spreadsheet-custom-draw-example/CS/WindowsFormsApp1/Form1.cs#L133

csharp
// Cancel default painting for the column header.
e.Handled = true;

winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L225

csharp
return;
e.Handled = true;
e.DrawDefault();

winforms-spreadsheet-custom-draw-example/VB/CustomDrawExample/Form1.vb#L30

vb
' Cancel default painting for the column header.
e.Handled = True

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L210

vb
If Not Equals(e.Cell.Worksheet.Name, "Invoice") OrElse Not Equals(cellReference, "A5") AndAlso Not Equals(cellReference, "A10") AndAlso Not Equals(cellReference, "F12") Then Return
e.Handled = True
e.DrawDefault()

See Also

CustomDrawObjectEventsArgs Class

CustomDrawObjectEventsArgs Members

DevExpress.XtraSpreadsheet Namespace