Back to Devexpress

VGridControlBase.CustomDrawCaption Event

windowsforms-devexpress-dot-xtraverticalgrid-dot-vgridcontrolbase-f3190d28.md

latest3.7 KB
Original Source

VGridControlBase.CustomDrawCaption Event

Allows you to paint the control’s caption.

Namespace : DevExpress.XtraVerticalGrid

Assembly : DevExpress.XtraVerticalGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.VerticalGrid

Declaration

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

Event Data

The CustomDrawCaption event's data class is DevExpress.XtraVerticalGrid.Events.CustomDrawCaptionEventArgs.

Remarks

The following example handles the CustomDrawCaption event to paint the Vertical Grid’s caption.

csharp
using DevExpress.XtraVerticalGrid.Events;

private void vGridControl1_CustomDrawCaption(object sender, CustomDrawCaptionEventArgs e) {
    LinearGradientBrush outerBrush = new LinearGradientBrush(e.Bounds, Color.LightBlue, Color.Blue, LinearGradientMode.Vertical);
    using(outerBrush) {
        e.Cache.FillRectangle(outerBrush, e.Bounds);
    }

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

    StringFormat outStrFormat = new StringFormat();
    outStrFormat.Alignment = StringAlignment.Center;
    outStrFormat.LineAlignment = StringAlignment.Center;
    e.Cache.DrawString(e.DisplayText, e.Appearance.Font, e.Cache.GetSolidBrush(Color.White), innerRect, outStrFormat);
    e.Handled = true;
}
vb
Imports DevExpress.XtraVerticalGrid.Events

Private Sub vGridControl1_CustomDrawCaption(ByVal sender As Object, ByVal e As CustomDrawCaptionEventArgs)
    Dim outerBrush As New LinearGradientBrush(e.Bounds, Color.LightBlue, Color.Blue, LinearGradientMode.Vertical)
    Using outerBrush
        e.Cache.FillRectangle(outerBrush, e.Bounds)
    End Using

    Dim innerRect As Rectangle = Rectangle.Inflate(e.Bounds, -3, -3)
    Dim innerBrush As New LinearGradientBrush(innerRect, Color.Blue, Color.LightBlue, LinearGradientMode.Vertical)
    Using innerBrush
        e.Cache.FillRectangle(innerBrush, e.Bounds)
    End Using

    Dim outStrFormat As New StringFormat()
    outStrFormat.Alignment = StringAlignment.Center
    outStrFormat.LineAlignment = StringAlignment.Center
    e.Cache.DrawString(e.DisplayText, e.Appearance.Font, e.Cache.GetSolidBrush(Color.White), innerRect, outStrFormat)
    e.Handled = True
End Sub

See Also

Caption

ShowCaption

Custom Painting

VGridControlBase Class

VGridControlBase Members

DevExpress.XtraVerticalGrid Namespace