windowsforms-devexpress-dot-xtranavbar-dot-navbarcontrol-c46ff0d0.md
Provides the ability to perform custom painting of a group client area’s foreground.
Namespace : DevExpress.XtraNavBar
Assembly : DevExpress.XtraNavBar.v25.2.dll
NuGet Package : DevExpress.Win
public event CustomDrawObjectEventHandler CustomDrawGroupClientForeground
Public Event CustomDrawGroupClientForeground As CustomDrawObjectEventHandler
The CustomDrawGroupClientForeground event's data class is CustomDrawObjectEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Appearance | Gets the painted element’s appearance settings. |
| Cache | Gets an object which specifies the storage for the most used pens, fonts and brushes. |
| Graphics | Gets an object used to paint the object. |
| Handled | Gets or sets a value specifying whether the control must perform default painting after an event handler has been executed. |
| ObjectInfo | Gets an object providing information on the element being painted. |
| RealBounds | Gets the bounding rectangle of the painted object. |
Write a CustomDrawGroupClientForeground event handler to perform custom painting of a group client area’s foreground. Set the CustomDrawObjectEventArgs.Handled property of the event parameter to true to disable default painting. Other properties of the event parameter allow you to identify the group whose client area is painted and provide all necessary information to paint it.
Use the CustomDrawGroupClientForeground event when you want to draw a group client area over the default painted background. If you don’t want default background painting, use the NavBarControl.CustomDrawGroupClientBackground event instead.
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.
The following sample code handles the NavBarControl.CustomDrawGroupClientForeground event to custom paint the text on a group’s client foreground. The group doesn’t contain any links initially and thus the NavBarGroup.CalcGroupClientHeight event is handled to specify the group’s height.
The image below shows the result.
using DevExpress.XtraNavBar.ViewInfo;
using DevExpress.XtraNavBar;
readonly Font mailFont = new Font("Verdana", 8, FontStyle.Bold);
readonly Font siteFont = new Font("Verdana", 8);
private void navBarControl1_CustomDrawGroupClientForeground(object sender,
CustomDrawObjectEventArgs e) {
// Identifying the processed group.
NavGroupClientInfoArgs info = e.ObjectInfo as NavGroupClientInfoArgs;
if(info.Group.Caption != "Support Info") return;
// Specifying the text rectangle.
Rectangle rect = e.RealBounds;
rect.Height /= 4;
// Formatting the output string.
using(var outStringFormat = new StringFormat()) {
outStringFormat.Alignment = StringAlignment.Near;
outStringFormat.LineAlignment = StringAlignment.Center;
// Painting the first string.
rect.Offset(0, rect.Height);
e.Cache.DrawString("E-mail:", mailFont,
Brushes.Black, rect, outStringFormat);
// Painting the second string.
rect.Offset(0, rect.Height);
e.Cache.DrawString("[email protected]", siteFont,
Brushes.Black, rect, outStringFormat);
}
// Prohibiting default painting.
e.Handled = true;
}
private void navBarGroup2_CalcGroupClientHeight(object sender,
NavBarCalcGroupClientHeightEventArgs e) {
e.Height = 70;
}
Imports DevExpress.XtraNavBar.ViewInfo
Imports DevExpress.XtraNavBar
Private ReadOnly mailFont As New Font("Verdana", 8, FontStyle.Bold)
Private ReadOnly siteFont As New Font("Verdana", 8)
Private Sub NavBarControl1_CustomDrawGroupClientForeground(ByVal sender As Object, _
ByVal e As CustomDrawObjectEventArgs) _
Handles NavBarControl1.CustomDrawGroupClientForeground
' Identifying the processed group.
Dim info As NavGroupClientInfoArgs = TryCast(e.ObjectInfo, NavGroupClientInfoArgs)
If info.Group.Caption <> "Support Info" Then
Return
End If
' Specifying the text rectangle.
Dim rect As Rectangle = e.RealBounds
rect.Height \= 4
' Formatting the output string.
Using outStringFormat = New StringFormat()
outStringFormat.Alignment = StringAlignment.Near
outStringFormat.LineAlignment = StringAlignment.Center
' Painting the first string.
rect.Offset(0, rect.Height)
e.Cache.DrawString("E-mail:", mailFont, Brushes.Black, rect, outStringFormat)
' Painting the second string.
rect.Offset(0, rect.Height)
e.Cache.DrawString("[email protected]", siteFont, Brushes.Black, rect, outStringFormat)
End Using
' Prohibiting default painting.
e.Handled = True
End Sub
Private Sub NavBarGroup2_CalcGroupClientHeight(ByVal sender As System.Object, _
ByVal e As NavBarCalcGroupClientHeightEventArgs) Handles NavBarGroup6.CalcGroupClientHeight
e.Height = 70
End Sub
See Also