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

NavBarControl.CustomDrawGroupCaption Event

Provides the ability to perform custom painting of group captions.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v18.2.dll

Declaration

public event CustomDrawNavBarElementEventHandler CustomDrawGroupCaption

Event Data

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

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

Remarks

Write a CustomDrawGroupCaption event handler to perform custom painting of group captions. Set the CustomDrawObjectEventArgs.Handled property of the event parameter to true to disable default painting. Other properties of the event parameter allow you to identify the group whose caption is painted and provide all necessary information to paint it.

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.CustomDrawGroupCaption event to custom paint the borders around group captions, fill in the background and paint its text. The background is filled in, in various different ways depending upon the state of the group’s caption.

The image below shows the look & feel of group captions in the normal, hot tracked and pressed states, respectively.

CustomDraw - GroupCaption

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

private void navBarControl1_CustomDrawGroupCaption(object sender, 
  CustomDrawNavBarElementEventArgs e) {
   // painting the borders
   Rectangle outerRect = e.RealBounds;
   SolidBrush outerBrush = new SolidBrush(Color.Orange);
   using(outerBrush) {
      e.Graphics.FillRectangle(outerBrush, outerRect);
   }

   // painting the background
   Rectangle innerRect = outerRect;
   innerRect.Inflate(-1, -1);
   LinearGradientBrush innerBrush;
   if (e.ObjectInfo.State == ObjectState.Hot)
      innerBrush = new LinearGradientBrush(innerRect, Color.PeachPuff, Color.Orange, 
        LinearGradientMode.Vertical);
   else if (e.ObjectInfo.State == ObjectState.Normal)
      innerBrush = new LinearGradientBrush(innerRect, Color.Orange, Color.PeachPuff, 
        LinearGradientMode.Horizontal);
   else
      innerBrush = new LinearGradientBrush(innerRect, Color.Orange, Color.PeachPuff, 
        LinearGradientMode.Vertical);
   using(innerBrush) {
      e.Graphics.FillRectangle(innerBrush, innerRect);
   }

   // painting the caption
   StringFormat outStringFormat = new StringFormat();
   outStringFormat.Alignment = StringAlignment.Near;
   outStringFormat.LineAlignment = StringAlignment.Center;
   SolidBrush textBrush = new SolidBrush(Color.White);
   NavGroupInfoArgs info = e.ObjectInfo as NavGroupInfoArgs;
   using(textBrush) {
      e.Graphics.DrawString(info.Group.Caption, e.Appearance.Font, textBrush, 
        innerRect, outStringFormat);
   }

   // prohibiting default painting
   e.Handled = true;
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomDrawGroupCaption 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.

See Also