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

CardView.CustomDrawCardCaption Event

Enables card captions to be custom painted.

Namespace: DevExpress.XtraGrid.Views.Card

Assembly: DevExpress.XtraGrid.v19.2.dll

Declaration

[DXCategory("CustomDraw")]
public event CardCaptionCustomDrawEventHandler CustomDrawCardCaption

Event Data

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

Property Description
Appearance Gets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
Bounds Returns a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs.
Cache Provides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more. Inherited from CustomDrawEventArgs.
CardCaption Gets or sets the current card’s caption.
CardInfo Gets an object that stores the information needed to paint a card.
Graphics A GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX hardware acceleration. Inherited from CustomDrawEventArgs.
Handled Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
RowHandle Gets the row handle identifying the card whose caption is painted.

The event data class exposes the following methods:

Method Description
DefaultDraw() Performs default painting of an element. Inherited from CustomDrawEventArgs.

Remarks

This event is raised each time a card caption needs to be repainted, and enables you to paint it manually. See the Custom Painting Basics and Custom Painting Scenarios topics for information on using custom draw events.

If you need to paint caption text as specified by the CardView.CardCaptionFormat property, use the CardView.GetCardCaption method to obtain the formatted text.

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 example lists a CardView.CustomDrawCardCaption event handler which we use to perform custom painting of card captions. Card captions are drawn differently for the focused and non focused cards.

CustomDrawCardCaption_2

private void cardView1_CustomDrawCardCaption(object sender, CardCaptionCustomDrawEventArgs e) {
    CardView view = sender as CardView;
    bool isFocusedCard = e.RowHandle == view.FocusedRowHandle;
    //The brush to draw the background of card captions.
    Brush backBrush, foreBrush;
    Color color1 = Color.FromArgb(142, 57, 80);
    Color color2 = Color.FromArgb(240, 140, 40);
    Color color3 = Color.FromArgb(70, 55, 94);
    Color color4 = Color.FromArgb(144, 84, 84);
    if (isFocusedCard) {
        backBrush = e.Cache.GetGradientBrush(e.Bounds, color1, color2, LinearGradientMode.ForwardDiagonal);
        foreBrush = Brushes.White;
    }
    else {
        backBrush = e.Cache.GetGradientBrush(e.Bounds, color3, color4, LinearGradientMode.ForwardDiagonal);
        foreBrush = Brushes.Coral;
    }
    Rectangle r = e.Bounds;
    r.Inflate(1, 0);
    e.Cache.FillRectangle(backBrush, r);
    // Draw the text.
    e.Appearance.DrawString(e.Cache, view.GetCardCaption(e.RowHandle),r, foreBrush);
    // Disable default painting.
    e.Handled = true;
}
See Also