Skip to main content

NavBarControl.CalcHintSize Event

Allows you to assign a custom hint size before a hint is displayed in the VSToolBoxView paint style.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v24.1.dll

NuGet Packages: DevExpress.Win, DevExpress.Win.Navigation

Declaration

public event NavBarCalcHintSizeEventHandler CalcHintSize

Event Data

The CalcHintSize event's data class is NavBarCalcHintSizeEventArgs. The following properties provide information specific to this event:

Property Description
Group Gets the group for which the hint is displayed. Inherited from NavBarCustomHintEventArgs.
HintInfo Gets an object providing information on the NavBarControl’s element for which the hint event was fired. Inherited from NavBarCustomHintEventArgs.
Link Gets the link for which the hint is displayed. Inherited from NavBarCustomHintEventArgs.
Size Gets or sets hint size.

Remarks

Write a CalcHintSize event handler to perform hint size corrections before a hint is displayed in the VSToolBoxView paint style. Typically, you need to correct the hint size to perform custom painting via the NavBarControl.CustomDrawHint event.

In other paint styles, the CalcHintSize event is not in effect. To customize the hint size and custom paint hints in these styles, handle the ToolTipController.CalcSize and ToolTipController.CustomDraw events of a tooltip controller object (for instance, of the DefaultToolTipController object).

In the VSToolBoxView paint style, hints are supported only for groups. The event’s parameter allows you to determine the group on which a hint is about to be displayed.

Hint text of groups/links is specified via the NavElement.Hint property. Write a NavBarControl.GetHint event handler to assign custom text and style to a hint before it is displayed. The NavBarControl.CalcHintSize event fires for each element whose hint text is not empty.

Example

The sample code below handles the NavBarControl.CustomDrawHint event to custom paint hints in the VSToolBoxView style. The NavBarControl.CalcHintSize event is handled to adjust the size of the hints in order to draw their outer borders.

The image below shows the result.

CustomDraw - Hints

using System.Drawing.Drawing2D;

private void navBarControl1_CalcHintSize(object sender, NavBarCalcHintSizeEventArgs e)
{
    // Enlarge the size of the hint to create space for drawing borders
    Size NewSize = e.Size;
    NewSize.Width += 18;
    NewSize.Height += 8;
    e.Size = new Size(NewSize.Width, NewSize.Height);
}

private void navBarControl1_CustomDrawHint(object sender, NavBarCustomDrawHintEventArgs e)
{
    // Obtain the object used to paint.
    Graphics gr = e.PaintArgs.Graphics;

    // Paint borders.
    LinearGradientBrush outerBrush = new LinearGradientBrush(e.Bounds, 
        Color.LightSkyBlue, Color.Blue, LinearGradientMode.Vertical);
    gr.FillRectangle(outerBrush, e.Bounds);
    outerBrush.Dispose();

    // Paint the background.
    // The background rectangle is reduced to make the borders visible.
    Rectangle innerRect = Rectangle.Inflate(e.Bounds, -3, -3);
    LinearGradientBrush innerBrush = new LinearGradientBrush(e.Bounds, 
        Color.Blue, Color.LightSkyBlue, LinearGradientMode.Vertical);
    gr.FillRectangle(innerBrush, innerRect);
    innerBrush.Dispose();

    // Format the output string.
    RectangleF textRect = new RectangleF(innerRect.Left, innerRect.Top, 
        innerRect.Width, innerRect.Height);
    StringFormat outStringFormat = new StringFormat();
    outStringFormat.Alignment = StringAlignment.Center;
    outStringFormat.LineAlignment = StringAlignment.Center;

    // Paint text.
    SolidBrush textBrush = new SolidBrush(Color.White);
    gr.DrawString(e.Hint, e.Appearance.Font, textBrush, textRect, outStringFormat);
    textBrush.Dispose();

    // Prohibit default hint painting         
    e.Handled = true;
}
See Also