下面的示例列示了一个 CardView.CustomDrawCardCaption 事件处理程序,用于执行自定义绘制卡片标题。 对获得焦点的和没有获得焦点的卡片绘制不同的卡片标题。
C# | 复制代码 |
---|---|
using System.Drawing.Drawing2D; using DevExpress.XtraGrid.Views.Card; private void cardView1_CustomDrawCardCaption(object sender, CardCaptionCustomDrawEventArgs e) { CardView view = sender as CardView; bool isFocused = e.RowHandle == view.FocusedRowHandle; // A brush to draw the background of the card caption. Brush backBrush; if(isFocused) backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.LavenderBlush, Color.Navy, LinearGradientMode.Vertical); else backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.Cornsilk, Color.DarkKhaki, LinearGradientMode.Vertical); // A brush to draw the text. Brush foreBrush = isFocused ? Brushes.White : Brushes.Chocolate; Rectangle r = e.Bounds; // Draw a 3D border. ControlPaint.DrawBorder3D(e.Graphics, r, Border3DStyle.RaisedInner); r.Inflate(-1, -1); // Fill the background. e.Graphics.FillRectangle(backBrush, r); r.Inflate(-2, 0); // Draw the text. e.Appearance.DrawString(e.Cache, view.GetCardCaption(e.RowHandle), r, foreBrush); // Default painting is not required. e.Handled = true; } |
Visual Basic | 复制代码 |
---|---|
Imports System.Drawing.Drawing2D Imports DevExpress.XtraGrid.Views.Card Private Sub CardView1_CustomDrawCardCaption(ByVal sender As Object, _ ByVal e As CardCaptionCustomDrawEventArgs) Handles CardView1.CustomDrawCardCaption Dim view As CardView = CType(sender, CardView) Dim isFocused As Boolean = e.RowHandle = view.FocusedRowHandle ' A brush to draw the background of the card caption. Dim backBrush As Brush If isFocused Then backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.LavenderBlush, Color.Navy, _ LinearGradientMode.Vertical) Else backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.Cornsilk, Color.DarkKhaki, _ LinearGradientMode.Vertical) End If ' A brush to draw the text. Dim foreBrush = IIf(isFocused, Brushes.White, Brushes.Chocolate) Dim r As Rectangle = e.Bounds ' Draw a 3D border. ControlPaint.DrawBorder3D(e.Graphics, r, Border3DStyle.RaisedInner) r.Inflate(-1, -1) ' Fill the background. e.Graphics.FillRectangle(backBrush, r) r.Inflate(-2, 0) ' Draw the text. e.Appearance.DrawString(e.Cache, view.GetCardCaption(e.RowHandle), r, foreBrush) ' Default painting is not required. e.Handled = True End Sub |