Back to Devexpress

How to: Custom Paint Card Field Values Depending on Field Positions

windowsforms-3035-controls-and-libraries-data-grid-examples-painting-how-to-custom-paint-card-field-values-depending-on-field-positions.md

latest1.9 KB
Original Source

How to: Custom Paint Card Field Values Depending on Field Positions

  • Nov 13, 2018

The following example handles the CardView.CustomDrawCardFieldValue event to custom paint card field values in the Price column.

csharp
private void cardView1_CustomDrawCardFieldValue(object sender, Views.Base.RowCellCustomDrawEventArgs e) {
    if (e.Column.FieldName != "Price") return;
    // The brush to fill the cell background.
    Color color1 = Color.FromArgb(40, 170, 225);
    Color color2 = Color.FromArgb(35, 80, 160);
    Brush brush = e.Cache.GetGradientBrush(e.Bounds, color1, color2, LinearGradientMode.Horizontal);
    e.Appearance.ForeColor = Color.White;
    e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold);
    e.Cache.FillRectangle(brush, e.Bounds);
    e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds);
    // Prevent default painting.
    e.Handled = true;
}
vb
Private Sub CardView1_CustomDrawCardFieldValue(sender As Object, e As DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs) Handles CardView1.CustomDrawCardFieldValue
    If e.Column.FieldName <> "Price" Then Return
    Dim color1 As Color = Color.FromArgb(40, 170, 225)
    Dim color2 As Color = Color.FromArgb(35, 80, 160)
    Dim brush As Brush = e.Cache.GetGradientBrush(e.Bounds, color1, color2, LinearGradientMode.Horizontal)
    e.Appearance.ForeColor = Color.White
    e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold)
    e.Cache.FillRectangle(brush, e.Bounds)
    e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds)
    e.Handled = True
End Sub