How to: Custom Paint the Group's Client Background
- 2 minutes to read
The following sample code handles the NavBarControl.CustomDrawGroupClientBackground event to fill the top and bottom portions of a group’s client background with linear gradient brushes of opposing color.
The image below shows the result.
using System.Drawing.Drawing2D;
using DevExpress.XtraNavBar.ViewInfo;
private void navBarControl1_CustomDrawGroupClientBackground(object sender,
CustomDrawObjectEventArgs e) {
// calculating the top and bottom part rectangles
Rectangle rect = e.RealBounds;
int halfHeight = rect.Height / 2;
Rectangle topRect = new Rectangle(rect.Left, rect.Top, rect.Width, halfHeight);
Rectangle bottomRect = new Rectangle(rect.Left, rect.Top + halfHeight,
rect.Width, halfHeight);
// creating brushes for the top and bottom parts
Color outerColor = Color.White;
Color innerColor = Color.LightSkyBlue;
LinearGradientBrush topBrush = new LinearGradientBrush(topRect, outerColor, innerColor,
LinearGradientMode.Vertical);
LinearGradientBrush bottomBrush = new LinearGradientBrush(bottomRect, innerColor,
outerColor, LinearGradientMode.Vertical);
// filling the top and bottom rectangles with the created brushes
e.Graphics.FillRectangle(topBrush, topRect);
e.Graphics.FillRectangle(bottomBrush, bottomRect);
// prohibiting default painting
e.Handled = true;
}