SpreadsheetControl.CustomDrawCellBackground Event
Provides the capability to perform custom painting of the cell background.
Namespace: DevExpress.XtraSpreadsheet
Assembly: DevExpress.XtraSpreadsheet.v18.2.dll
Declaration
Event Data
The CustomDrawCellBackground event's data class is CustomDrawCellBackgroundEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
BackColor | Gets or sets the background color of the painted cell. |
Bounds | Returns the bounding rectangle of the drawing area. Inherited from CustomDrawCellEventArgsBase. |
Cache | Gets an object which specifies the storage for the pens, fonts and brushes. Inherited from CustomDrawObjectEventsArgs. |
Cell | Gets the worksheet cell being painted. Inherited from CustomDrawCellEventArgsBase. |
FillBounds | Returns the bounding rectangle of the drawing area for painting the cell background. Inherited from CustomDrawCellEventArgsBase. |
Graphics | Gets an object used for painting. Inherited from CustomDrawObjectEventsArgs. |
Handled | Gets or sets whether an event is handled. If true, the default actions are not required. Inherited from CustomDrawObjectEventsArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
DrawDefault() | Renders the element using the default drawing mechanism. Inherited from CustomDrawObjectEventsArgs. |
Remarks
The CustomDrawCellBackground event is raised before a worksheet Cell is painted. Event arguments properties provide the objects and information required to paint the cell.
Set the CustomDrawObjectEventsArgs.Handled property to true to cancel default painting. Use the CustomDrawObjectEventsArgs.DrawDefault method to perform default painting within the event handler.
Note
The CustomDrawCellBackground event is fired only for existing cells, i.e., the cells that have formatting or content different from the default. The Worksheet.GetUsedRange method returns a range that comprises existing cells.
The following code paints cells containing a formula (determined by the Range.HasFormula value) with a hatched brush. Note that the CustomDrawCellEventArgsBase.FillBounds property instead of the CustomDrawCellEventArgsBase.Bounds property is used to get the rectangle to fill.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/xtraspreadsheet-custom-draw-examples-e5044
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet;
void spreadsheetControl1_CustomDrawCellBackground(object sender, CustomDrawCellBackgroundEventArgs e)
{
if (e.Cell.HasFormula)
{
e.Handled = true;
System.Drawing.Drawing2D.HatchBrush hBrush = new System.Drawing.Drawing2D.HatchBrush(
System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal,
Color.LightGray,
Color.White);
e.Graphics.FillRectangle(hBrush,e.FillBounds);
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawCellBackground event.
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.