本示例展示了通过接管 CardView.CustomDrawCardFieldValue 事件,执行 卡片字段取值单元格 的自定义绘制。
C# | 复制代码 |
---|---|
using System.Drawing; using System.Drawing.Drawing2D; using DevExpress.XtraGrid.Views.Base; private void cardView1_CustomDrawCardFieldValue(object sender, RowCellCustomDrawEventArgs e) { // The brush to fill the cell background. Brush brush = e.Cache.GetGradientBrush(e.Bounds, Color.Aquamarine, Color.DarkSeaGreen, LinearGradientMode.Horizontal); // Change the brush and appearance settings for drawing the SubTotal field value. if(e.Column.FieldName == "SubTotal") { brush = e.Cache.GetGradientBrush(e.Bounds, Color.White, Color.SkyBlue, LinearGradientMode.Horizontal); e.Appearance.ForeColor = Color.Indigo; e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold); } // Fill the background with the specified brush. e.Graphics.FillRectangle(brush, e.Bounds); // Draw the value using the settings specified by the e.Appearance parameter. e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds); // Prevent default painting. e.Handled = true; } |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraGrid.Views.Base Imports System.Drawing.Drawing2D Private Sub CardView1_CustomDrawCardFieldValue(ByVal sender As Object, _ ByVal e As .RowCellCustomDrawEventArgs) Handles CardView1.CustomDrawCardFieldValue ' The brush to fill the cell background. Dim brush As Brush = e.Cache.GetGradientBrush(e.Bounds, Color.Aquamarine, _ Color.DarkSeaGreen, LinearGradientMode.Horizontal, 2) ' Change the brush and appearance settings for drawing the SubTotal field value. If e.Column.FieldName = "SubTotal" Then brush = e.Cache.GetGradientBrush(e.Bounds, Color.White, Color.SkyBlue, _ LinearGradientMode.Horizontal) e.Appearance.ForeColor = Color.Indigo e.Appearance.Font = e.Cache.GetFont(e.Appearance.Font, FontStyle.Bold) End If ' Fill the background. e.Graphics.FillRectangle(brush, e.Bounds) ' Draw the value using the settings specified by the e.Appearance parameter. e.Appearance.DrawString(e.Cache, e.DisplayText, e.Bounds) ' Prevent default painting. e.Handled = True End Sub |