windowsforms-3034-controls-and-libraries-data-grid-examples-painting-how-to-display-a-custom-image-within-a-group-panel.md
In this example, the GridView.CustomDrawGroupPanel event is handled to perform group panel custom painting. The panel is filled with a gradient brush. Then an image is painted at the panel’s right edge.
Image groupPanelImage;
private void Form1_Load(object sender, EventArgs e) {
groupPanelImage = Image.FromFile(@"C:\Work\Pictures\Icon.png");
gridView1.Appearance.GroupPanel.ForeColor = Color.Black;
}
private void gridView1_CustomDrawGroupPanel(object sender, DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs e) {
//Define a linear gradient brush
Color color1 = Color.FromArgb(244, 132, 38);
Brush brush = e.Cache.GetGradientBrush(e.Bounds, color1, Color.Bisque,
System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
//Fill the group panel
e.Cache.FillRectangle(brush, e.Bounds);
//Draw a custom image at the panel's right edge
Rectangle r = new Rectangle(e.Bounds.X + e.Bounds.Width - groupPanelImage.Size.Width - 5,
e.Bounds.Y + (e.Bounds.Height - groupPanelImage.Size.Height) / 2, groupPanelImage.Width, groupPanelImage.Height);
e.Cache.DrawImageUnscaled(groupPanelImage, r);
e.Handled = true;
}
Dim groupPanelImage As Image
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
groupPanelImage = Image.FromFile("C:\Work\Pictures\Icon.png")
GridView1.Appearance.GroupPanel.ForeColor = Color.Black
End Sub
Private Sub GridView1_CustomDrawGroupPanel(sender As Object, e As DevExpress.XtraGrid.Views.Base.CustomDrawEventArgs) Handles GridView1.CustomDrawGroupPanel
'Define a linear gradient brush
Dim color1 As Color = Color.FromArgb(244, 132, 38)
Dim brush As Brush = e.Cache.GetGradientBrush(e.Bounds, color1, Color.Bisque, LinearGradientMode.Horizontal)
'Fill the group panel
e.Cache.FillRectangle(brush, e.Bounds)
'Draw a custom image at the panel's right edge
Dim r As Rectangle = New Rectangle(e.Bounds.X + e.Bounds.Width - groupPanelImage.Size.Width - 5,
e.Bounds.Y + (e.Bounds.Height - groupPanelImage.Size.Height) / 2, groupPanelImage.Width, groupPanelImage.Height)
e.Cache.DrawImageUnscaled(groupPanelImage, r)
e.Handled = True
End Sub