Skip to main content

NavBarControl.CustomDrawGroupCaption Event

Provides the ability to perform custom painting of group captions.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v24.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

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.

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) {
    Rectangle outerRect = e.RealBounds;
    e.Cache.FillRectangle(Brushes.Orange, 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.Cache.FillRectangle(innerBrush, innerRect);

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

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