Back to Devexpress

GroupControl.CustomDrawCaption Event

windowsforms-devexpress-dot-xtraeditors-dot-groupcontrol-a070ba3a.md

latest6.9 KB
Original Source

GroupControl.CustomDrawCaption Event

Allows you to custom paint the caption region.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[DXCategory("Appearance")]
public virtual event GroupCaptionCustomDrawEventHandler CustomDrawCaption
vb
<DXCategory("Appearance")>
Public Overridable Event CustomDrawCaption As GroupCaptionCustomDrawEventHandler

Event Data

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

PropertyDescription
CaptionBoundsGets the painted caption’s bounding rectangle.
InfoGets information on the painted group.
PainterProvides access to the object that performs paint operations. Inherited from ObjectCustomDrawEventArgs.

The event data class exposes the following methods:

MethodDescription
DefaultDrawBackground()Performs default painting of the control’s caption background.
DefaultDrawButtons()Performs default painting of the buttons embedded in the control’s caption.
DefaultDrawImage()Performs default painting of the control’s caption image.
DefaultDrawText()Performs default painting of the text in the control’s caption.

Remarks

The CustomDrawCaption event allows you to custom paint the caption. Use the GroupCaptionCustomDrawEventArgs.Info event parameter to obtain the caption’s display settings (for instance, the text, button bounds, etc.).

To draw custom information, use the methods provided by the Cache or Graphics event parameter.

When you handle the CustomDrawCaption event, you can invoke the default rendering of the caption or its individual elements with the following methods:

  • DefaultDraw - Performs the default rendering of the caption (including all its elements)
  • DefaultDrawBackground - Performs the default rendering of the caption’s background.
  • DefaultDrawButtons - Performs the default rendering of the caption’s buttons (GroupControl.CustomHeaderButtons)
  • DefaultDrawImage - Performs the default rendering of the caption’s image (GroupControl.CaptionImageOptions)
  • DefaultDrawText - Performs the default rendering of the tab’s text (GroupControl.Text)

Set the Handled event parameter to true to indicate that you have handled the CustomDrawCaption event and no default painting is required after your event handler is completed. If the event’s Handled parameter is set to false (the default value), the default painting mechanism will automatically be invoked after your custom draw event handler is completed. The default painting mechanism overrides all rendering you may have performed previously.

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.

csharp
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.Cache.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.Cache.FillRectangle(innerBrush, e.CaptionBounds);
   }

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

   e.Handled = true;
}
vb
Imports System.Drawing.Drawing2D
Imports DevExpress.XtraEditors
' ...

Private Sub GroupControl1_CustomDrawCaption(ByVal sender As Object, _
ByVal e As GroupCaptionCustomDrawEventArgs) _
Handles GroupControl1.CustomDrawCaption
   Dim outerBrush As LinearGradientBrush = New LinearGradientBrush(e.CaptionBounds, _
     Color.LightBlue, Color.Blue, LinearGradientMode.Vertical)
   e.Cache.FillRectangle(outerBrush, e.CaptionBounds)
   outerBrush.Dispose()

   Dim innerRect As Rectangle = Rectangle.Inflate(e.CaptionBounds, -3, -3)
   Dim innerBrush As LinearGradientBrush = New LinearGradientBrush(innerRect, _
     Color.Blue, Color.LightBlue, LinearGradientMode.Vertical)
   e.Cache.FillRectangle(innerBrush, e.CaptionBounds)
   innerBrush.Dispose()

   Dim textRect As New RectangleF(innerRect.Left, innerRect.Top, _
     innerRect.Width, innerRect.Height)
   Dim outStrFormat As StringFormat = New StringFormat()
   outStrFormat.Alignment = StringAlignment.Center
   outStrFormat.LineAlignment = StringAlignment.Center
   e.Cache.DrawString(e.Info.Caption, e.Info.AppearanceCaption.Font, _
     e.Cache.GetSolidBrush(Color.White), textRect, outStrFormat)

   e.Handled = True
End Sub

See Also

GroupControl Class

GroupControl Members

DevExpress.XtraEditors Namespace