在本例中,我们以特定的方式绘制 分组面板 —— 通过接管 GridView.CustomDrawGroupPanel 事件来实现。 首先,使用渐变刷填充面板。 然后,在面板的右侧绘制一幅自定义图像。

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

Bitmap groupPanelImage;
private void frmMain_Load(object sender, System.EventArgs e) {
    //...
    groupPanelImage = (Bitmap)Bitmap.FromStream(
      Assembly.GetExecutingAssembly().GetManifestResourceStream(
      "GridCustomDraw.Images.logo_c.gif"));
    groupPanelImage.MakeTransparent();
}

private void advBandedGridView1_CustomDrawGroupPanel(object sender, CustomDrawEventArgs e) {
    //Define a linear gradient brush
    Brush brush = e.Cache.GetGradientBrush(e.Bounds, Color.Sienna, Color.Bisque, 
      System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
    //Fill the group panel
    e.Graphics.FillRectangle(brush, e.Bounds);
    //Draw a glyph at the right edge of the panel
    Image img = groupPanelImage;
    Rectangle r = new Rectangle(e.Bounds.X + e.Bounds.Width - img.Size.Width - 5, 
      e.Bounds.Y + (e.Bounds.Height - img.Size.Height) / 2, img.Width, img.Height);
    e.Graphics.DrawImageUnscaled(img, r);
    e.Handled = true;
}

Visual BasicCopyCode image复制代码
Imports System.Reflection
Imports DevExpress.XtraGrid.Views.Base

Dim groupPanelImage As Bitmap
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
    '...
    groupPanelImage = CType(Bitmap.FromStream( _
      Assembly.GetExecutingAssembly().GetManifestResourceStream( _
      "GridCustomDraw.logo_c.gif")), Bitmap)
    groupPanelImage.MakeTransparent()
End Sub

Private Sub advBandedGridView1_CustomDrawGroupPanel(ByVal sender As Object, _
ByVal e As CustomDrawEventArgs) Handles advBandedGridView1.CustomDrawGroupPanel
    'Define a linear gradient brush
    Dim brush As Brush = e.Cache.GetGradientBrush(e.Bounds, Color.Sienna, Color.Bisque, _
      System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
    'Fill the group panel
    e.Graphics.FillRectangle(brush, e.Bounds)
    'Draw a glyph at the right edge of the panel
    Dim img As Image = groupPanelImage
    Dim r As Rectangle = New Rectangle(e.Bounds.X + e.Bounds.Width - img.Size.Width - 5, _
      e.Bounds.Y + (e.Bounds.Height - img.Size.Height) / 2, img.Width, img.Height)
    e.Graphics.DrawImageUnscaled(img, r)
    e.Handled = True
End Sub