How to: Customize Display Information via Custom Draw Events
- 2 minutes to read
To customize the NavBarControl appearance, you can use two approaches:
Completely repaint a visual element
For example, use the NavBarControl.CustomDrawBackground event to draw a string at the bottom. The CustomDrawObjectEventArgs.Handled event parameter should be set to true to disable the default paint algorithm.
Customize paint parameters
For example, use the NavBarControl.CustomDrawLink event to display in bold hot-tracked links.
using System.Drawing.Drawing2D;
using DevExpress.XtraNavBar.ViewInfo;
using DevExpress.Utils.Drawing;
private void navBarControl1_CustomDrawBackground(object sender, CustomDrawObjectEventArgs e) {
Rectangle rect = e.RealBounds;
Graphics gr = e.ObjectInfo.Graphics;
// Create a new font for the string.
Font stringFont = new Font("Verdana", 8);
// Create a brush used to draw the string.
LinearGradientBrush stringBrush = new LinearGradientBrush(rect, Color.Blue,
Color.Red, LinearGradientMode.Horizontal);
// Calculate string rectangle.
int stringHeight = Convert.ToInt16(gr.MeasureString("www.devexpress.com",
stringFont).Height);
Rectangle stringRect = new Rectangle(rect.Left, rect.Bottom - stringHeight,
rect.Width, stringHeight);
// Format string output.
StringFormat outStringFormat = new StringFormat();
outStringFormat.Alignment = StringAlignment.Center;
// Draw the string.
gr.DrawString("www.devexpress.com", stringFont, stringBrush, stringRect, outStringFormat);
// Prohibit default background painting
e.Handled = true;
}
private void navBarControl1_CustomDrawLink(object sender, CustomDrawNavBarElementEventArgs e) {
// If a link is not hot tracked or pressed it is drawn in the normal way.
if (e.ObjectInfo.State == ObjectState.Hot || e.ObjectInfo.State == ObjectState.Pressed) {
NavLinkInfoArgs linkInfo = e.ObjectInfo as NavLinkInfoArgs;
// Customize the font style.
e.Appearance.FontStyleDelta = FontStyle.Bold;
}
}