SpreadsheetControl.CustomDrawColumnHeaderBackground Event

Enables the column header background to be painted manually.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v21.2.dll

Declaration

public event CustomDrawColumnHeaderBackgroundEventHandler CustomDrawColumnHeaderBackground

Event Data

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

Property Description
Appearance Provides access to the properties that control the appearance of a worksheet header. Inherited from CustomDrawHeaderEventArgsBase.
BackColor Gets the background color of the header. Inherited from CustomDrawHeaderEventArgsBase.
Bounds Gets the header’s bound rectangle. Inherited from CustomDrawHeaderEventArgsBase.
Cache Gets an object that serves as the storage for pens, fonts and brushes. Inherited from CustomDrawObjectEventsArgs.
ColumnIndex Returns the column index of the column header being painted.
Control Provides access to the SpreadsheetControl that raised the event. Inherited from CustomDrawHeaderEventArgsBase.
Font Gets the font used to paint the header caption. Inherited from CustomDrawHeaderEventArgsBase.
ForeColor Gets the color used to paint the header caption text. Inherited from CustomDrawHeaderEventArgsBase.
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.
IsHovered Gets whether a mouse is currently over the worksheet header. Inherited from CustomDrawHeaderEventArgsBase.
IsSelected Gets whether the current column contains selected cell(s). Inherited from CustomDrawHeaderEventArgsBase.
Text Gets the text of the header caption. Inherited from CustomDrawHeaderEventArgsBase.

The event data class exposes the following methods:

Method Description
DrawDefault() Renders the element using the default drawing mechanism. Inherited from CustomDrawObjectEventsArgs.

Remarks

The CustomDrawColumnHeaderBackground event is raised before a column header is painted. Event arguments properties provide the objects and information required to paint the column header background.

Set the CustomDrawObjectEventsArgs.Handled property to true to cancel default painting. Use the CustomDrawObjectEventsArgs.DrawDefault method to perform default painting within the event handler.

The following code snippet demonstrates how to change the background color for column headers. This example applies a dark red color to a column header under the mouse pointer or if a header belongs to a column with the active cell:

Handle the CustomDrawColumnHeaderBackground event

View Example: Use Custom Draw Events to Customize the Appearance of Spreadsheet Elements

using System;
using System.Drawing;
using DevExpress.Spreadsheet;
using DevExpress.XtraSpreadsheet;
// ...
private void spreadsheetControl1_CustomDrawColumnHeaderBackground(object sender, 
    CustomDrawColumnHeaderBackgroundEventArgs e)
{
    // Cancel default painting for the column header background.
    e.Handled = true;

    // If the column header is under the mouse pointer or the column contains the active cell,
    // paint the column header background in Color 1.
    // Otherwise, use Color 2.
    if (e.ColumnIndex <= 4) {
        var backColor = e.IsHovered || (e.ColumnIndex == spreadsheetControl1.ActiveCell.ColumnIndex) ?
            //Color 1
            Color.FromArgb(200, 44, 74) :
            //Color 2
            Color.FromArgb(91, 155, 213);
        e.Cache.FillRectangle(e.Cache.GetSolidBrush(backColor), e.Bounds);
    }
}
See Also