Back to Devexpress

NavBarControl.CustomDrawHint Event

windowsforms-devexpress-dot-xtranavbar-dot-navbarcontrol-76fd16f5.md

latest8.4 KB
Original Source

NavBarControl.CustomDrawHint Event

Provides the capability to perform custom painting of hints in the VSToolBoxView paint style.

Namespace : DevExpress.XtraNavBar

Assembly : DevExpress.XtraNavBar.v25.2.dll

NuGet Package : DevExpress.Win

Declaration

csharp
public event NavBarCustomDrawHintEventHandler CustomDrawHint
vb
Public Event CustomDrawHint As NavBarCustomDrawHintEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted hint’s appearance settings.
BoundsGets the hint’s bound rectangle.
GroupGets the group for which the hint is displayed. Inherited from NavBarCustomHintEventArgs.
HandledGets or sets a value specifying whether the control should perform default hint painting.
HintGets the hint text.
HintInfoGets an object providing information on the NavBarControl’s element for which the hint event was fired. Inherited from NavBarCustomHintEventArgs.
LinkGets the link for which the hint is displayed. Inherited from NavBarCustomHintEventArgs.
PaintArgsGets an object containing painting parameters.

Remarks

Write a CustomDrawHint event handler to perform custom painting of hints when the NavBarControl is painted using the VSToolBoxView style. In the VSToolBoxView style, hints are supported only for groups. In other paint styles, the CustomDrawHint event is not in effect. To custom paint hints in these styles, use the ToolTipController.CustomDraw event of a ToolTipController object (for instance, of the DefaultToolTipController object).

While handling the CustomDrawHint event, set the event’s NavBarCustomDrawHintEventArgs.Handled parameter to true , to disable default painting. Other properties of the event parameter allow you to identify the group whose hint is painted, and provide all necessary information to paint.

Important

Do not change cell values, modify the control’s layout, or change the control’s object model in the events used for custom control painting. Actions that update the layout can cause the control to malfunction.

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.

csharp
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;
}
vb
Imports DevExpress.XtraNavBar
Imports System.Drawing.Drawing2D

Private Sub NavBarControl1_CalcHintSize(ByVal sender As System.Object, _
ByVal e As NavBarCalcHintSizeEventArgs) Handles NavBarControl1.CalcHintSize
    ' Enlarge the size of the hint to create space for drawing borders
    Dim NewSize As Size = e.Size
    NewSize.Width += 18
    NewSize.Height += 8
    e.Size = New Size(NewSize.Width, NewSize.Height)
End Sub

Private Sub NavBarControl1_CustomDrawHint(ByVal sender As System.Object, _
ByVal e As NavBarCustomDrawHintEventArgs) Handles NavBarControl1.CustomDrawHint
    ' Obtain the object used to paint.
    Dim gr As Graphics = e.PaintArgs.Graphics

    ' Paint borders.
    Dim outerBrush As LinearGradientBrush = 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.
    Dim innerRect As Rectangle = Rectangle.Inflate(e.Bounds, -3, -3)
    Dim innerBrush As LinearGradientBrush = New LinearGradientBrush(e.Bounds, _
        Color.Blue, Color.LightSkyBlue, LinearGradientMode.Vertical)
    gr.FillRectangle(innerBrush, innerRect)
    innerBrush.Dispose()

    ' Format the output string.
    Dim textRect As RectangleF = New RectangleF(innerRect.Left, innerRect.Top, _
        innerRect.Width, innerRect.Height)
    Dim outStringFormat As StringFormat = New StringFormat()
    outStringFormat.Alignment = StringAlignment.Center
    outStringFormat.LineAlignment = StringAlignment.Center

    ' Paint text.
    Dim textBrush As SolidBrush = New SolidBrush(Color.White)
    gr.DrawString(e.Hint, e.Appearance.Font, textBrush, textRect, outStringFormat)
    textBrush.Dispose()

    ' Prohibit default hint painting         
    e.Handled = True
End Sub

See Also

CustomDrawGroupCaption

CustomDrawLink

CustomDrawBackground

CustomDrawGroupClientBackground

CustomDrawGroupClientForeground

CustomDraw

CalcSize

NavBarControl Class

NavBarControl Members

DevExpress.XtraNavBar Namespace