本示例展示了如何定制 分组脚注 及其单元格,这是通过接管 GridView.CustomDrawRowFooterGridView.CustomDrawRowFooterCell 事件来实现的。

使用渐变刷以凸起效果绘制分组脚注。

通过 CustomDrawObjectEventArgs.Painter 参数的 DrawObject 方法绘制脚注单元格。

C#CopyCode image复制代码
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;

private void gridView1_CustomDrawRowFooter(object sender, RowObjectCustomDrawEventArgs e) {     
    Brush brush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, 
      Color.FromArgb(209, 227, 241), Color.FromArgb(68, 121, 191), 90);
    e.Graphics.FillRectangle(brush, e.Bounds);
    ControlPaint.DrawBorder3D(e.Graphics, e.Bounds, Border3DStyle.RaisedInner);
    //Prevent default painting
    e.Handled = true;
}

private void gridView1_CustomDrawRowFooterCell(object sender, FooterCellCustomDrawEventArgs e) {
    //Change the background color
    e.Appearance.BackColor = Color.Lavender;
    //Paint using the new background color
    e.Painter.DrawObject(e.Info);
    //Prevent default painting
    e.Handled = true;
}
Visual BasicCopyCode image复制代码
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraGrid.Views.Grid

Private Sub gridView1_CustomDrawRowFooter(ByVal sender As Object, _
ByVal e As RowObjectCustomDrawEventArgs) Handles gridView1.CustomDrawRowFooter
    Dim brush As Brush = New System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, _
      Color.FromArgb(209, 227, 241), Color.FromArgb(68, 121, 191), 90)
    e.Graphics.FillRectangle(brush, e.Bounds)
    ControlPaint.DrawBorder3D(e.Graphics, e.Bounds, Border3DStyle.RaisedInner)
    'Prevent default painting
    e.Handled = True
End Sub

Private Sub gridView1_CustomDrawRowFooterCell(ByVal sender As Object, _
ByVal e As FooterCellCustomDrawEventArgs) Handles gridView1.CustomDrawRowFooterCell
    'Change the background color
    e.Appearance.BackColor = Color.Lavender
    'Paint using the new background color
    e.Painter.DrawObject(e.Info)
    'Prevent default painting
    e.Handled = True
End Sub