CardView.CustomDrawCardCaption Event
Enables card captions to be custom painted.
Namespace: DevExpress.XtraGrid.Views.Card
Assembly: DevExpress.XtraGrid.v24.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. |
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawEventArgs. |
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. 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
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 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.
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;
}