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

GroupControl.CustomDrawCaption Event

Enables group caption to be custom painted.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.Utils.v18.1.dll

Declaration

[DXCategory("Appearance")]
public event GroupCaptionCustomDrawEventHandler CustomDrawCaption

Event Data

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

Property Description
CaptionBounds Gets the painted caption’s bounding rectangle.
Info Gets information on the painted group.

The event data class exposes the following methods:

Method Description
DefaultDraw() Performs default painting of this element.

Remarks

This event is raised each time a group caption needs to be repainted and it provides the ability to paint it manually. All the information required to paint the group caption can be obtained via the event parameter’s GroupCaptionCustomDrawEventArgs.Info property. Note that the Handled parameter must be set to true to prohibit the default painting.

Example

The following example demonstrates how to handle the GroupControl.CustomDrawCaption event to manually paint a group control’s caption.

The image below shows the result.

GroupControl_CustomDrawCaption

using System.Drawing.Drawing2D;
using DevExpress.XtraEditors;
// ...

private void groupControl1_CustomDrawCaption(object sender, GroupCaptionCustomDrawEventArgs e) {
   LinearGradientBrush outerBrush = new LinearGradientBrush(e.CaptionBounds, 
     Color.LightBlue, Color.Blue, LinearGradientMode.Vertical);
   using(outerBrush) {
      e.Graphics.FillRectangle(outerBrush, e.CaptionBounds);
   }

   Rectangle innerRect = Rectangle.Inflate(e.CaptionBounds, -3, -3);
   LinearGradientBrush innerBrush = new LinearGradientBrush(innerRect, Color.Blue, 
     Color.LightBlue, LinearGradientMode.Vertical);
   using(innerBrush) {
      e.Graphics.FillRectangle(innerBrush, e.CaptionBounds);
   }

   StringFormat outStrFormat = new StringFormat();
   outStrFormat.Alignment = StringAlignment.Center;
   outStrFormat.LineAlignment = StringAlignment.Center;
   e.Graphics.DrawString(e.Info.Caption, e.Info.AppearanceCaption.Font, 
     e.Cache.GetSolidBrush(Color.White), innerRect, outStrFormat);

   e.Handled = true;
}
See Also