Skip to main content
A newer version of this page is available. .

NavBarControl.CustomDrawBackground Event

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

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v18.2.dll

Declaration

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.

Remarks

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.

Important

Never change cell values or modify the control’s layout on this event, or any other event designed to tune the control’s appearance. Any action that causes a layout update can cause the control to malfunction.

Example

The following sample code handles the NavBarControl.CustomDrawBackground event to fill the XtraNavBarControl’s background with a linear gradient brush and draw a string at the bottom.

The image below shows the result.

CustomDraw - Background

using System.Drawing;
using System.Drawing.Drawing2D;
using DevExpress.XtraNavBar.ViewInfo;

private void navBarControl1_CustomDrawBackground(object sender, CustomDrawObjectEventArgs e) {

   Rectangle rect = e.RealBounds;
   Graphics gr = e.ObjectInfo.Graphics;

   // creating a brush and filling the background with it
   LinearGradientBrush backBrush = new LinearGradientBrush(rect, Color.Pink, 
     Color.LightSkyBlue, LinearGradientMode.Horizontal);
   gr.FillRectangle(backBrush, rect);

   // creating a new font for the string
   Font stringFont = new Font("Verdana", 8);
   // creating a brush used to draw the string
   LinearGradientBrush stringBrush = new LinearGradientBrush(rect, Color.Blue, 
     Color.Red, LinearGradientMode.Horizontal);
   // calculating string rectangle 
   int stringHeight = Convert.ToInt16(gr.MeasureString("www.devexpress.com", 
     stringFont).Height);
   Rectangle stringRect = new Rectangle(rect.Left, rect.Bottom - stringHeight, 
     rect.Width, stringHeight);
   // formatting string output
   StringFormat outStringFormat = new StringFormat();
   outStringFormat.Alignment = StringAlignment.Center;

   // drawing the string
   gr.DrawString("www.devexpress.com", stringFont, stringBrush, stringRect, outStringFormat);

   // prohibiting default background painting
   e.Handled = true; 
}
See Also