NavBarControl.CustomDrawBackground Event

Provides the capability to custom paint the control’s background.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v21.2.dll


public event CustomDrawObjectEventHandler CustomDrawBackground

Event Data

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

Property Description
Appearance Gets the painted element’s appearance settings.
Cache Gets an object which specifies the storage for the most used pens, fonts and brushes.
Graphics Gets an object used to paint the object.
Handled Gets or sets a value specifying whether the control must perform default painting after an event handler has been executed.
ObjectInfo Gets an object providing information on the element being painted.
RealBounds Gets the bounding rectangle of the painted object.


Write a CustomDrawBackground event handler to perform custom painting of the control’s background. Set the CustomDrawObjectEventArgs.Handled property of the event parameter to true to disable default background painting. Other event parameters provide you with all the necessary information to perform background painting.

Group captions and client areas occupy the entire control’s area in certain paint styles. Writing a CustomDrawBackground event has no impact in such a case.


Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.


The code below handles the NavBarControl.CustomDrawBackground event to fill the background with a linear gradient brush.


using System.Drawing;

private void navBarControl1_CustomDrawBackground(object sender, CustomDrawObjectEventArgs e) {
    // Get the background bounds.
    Rectangle rect = e.RealBounds;

    // Get a gradient brush and fill the background. 
    Brush backBrush = e.Cache.GetGradientBrush(rect, Color.Pink, Color.LightSkyBlue, LinearGradientMode.Horizontal);
    e.Cache.FillRectangle(backBrush, rect);

    // Prevent the default paint algorithm from being invoked.
    e.Handled = true;
See Also