windowsforms-4908-controls-and-libraries-navigation-controls-navigation-bar-examples-appearance-how-to-custom-paint-the-groups-client-background.md
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, DevExpress.XtraNavBar.ViewInfo.CustomDrawObjectEventArgs e) {
// calculate 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);
// create 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);
// fill the top and bottom rectangles with the created brushes
e.Cache.FillRectangle(topBrush, topRect);
e.Cache.FillRectangle(bottomBrush, bottomRect);
topBrush.Dispose();
bottomBrush.Dispose();
// prohibit default painting
e.Handled = true;
}
Imports System.Drawing.Drawing2D
Imports DevExpress.XtraNavBar.ViewInfo
Private Sub NavBarControl1_CustomDrawGroupClientBackground(sender As Object, e As CustomDrawObjectEventArgs) Handles NavBarControl1.CustomDrawGroupClientBackground
' calculate the top and bottom part rectangles
Dim Rect As Rectangle = e.RealBounds
Dim HalfHeight = Rect.Height / 2
Dim TopRect As New Rectangle(Rect.Left, Rect.Top, Rect.Width, HalfHeight)
Dim BottomRect As New Rectangle(Rect.Left, Rect.Top + HalfHeight, Rect.Width, HalfHeight)
' create brushes for the top and bottom parts
Dim OuterColor As Color = Color.White
Dim InnerColor As Color = Color.LightSkyBlue
Dim TopBrush As New LinearGradientBrush(TopRect, OuterColor, InnerColor,
LinearGradientMode.Vertical)
Dim BottomBrush As New LinearGradientBrush(BottomRect, InnerColor, OuterColor,
LinearGradientMode.Vertical)
' fill the top and bottom rectangles with the created brushes
e.Cache.FillRectangle(TopBrush, TopRect)
e.Cache.FillRectangle(BottomBrush, BottomRect)
TopBrush.Dispose()
BottomBrush.Dispose()
' prohibit default painting
e.Handled = True
End Sub