Skip to main content
A newer version of this page is available. .

How to: Customize Display Information via Custom Draw Events

  • 2 minutes to read

To customize the NavBarControl appearance, you can use two approaches:

custom_draw_events

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;
    }
}