Back to Devexpress

NavBarControl.CustomDrawBackground Event

windowsforms-devexpress-dot-xtranavbar-dot-navbarcontrol-43dca5d3.md

latest4.8 KB
Original Source

NavBarControl.CustomDrawBackground Event

Provides the capability to custom paint the control’s background.

Namespace : DevExpress.XtraNavBar

Assembly : DevExpress.XtraNavBar.v25.2.dll

NuGet Package : DevExpress.Win

Declaration

csharp
public event CustomDrawObjectEventHandler CustomDrawBackground
vb
Public Event CustomDrawBackground As CustomDrawObjectEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings.
CacheGets an object which specifies the storage for the most used pens, fonts and brushes.
GraphicsGets an object used to paint the object.
HandledGets or sets a value specifying whether the control must perform default painting after an event handler has been executed.
ObjectInfoGets an object providing information on the element being painted.
RealBoundsGets the bounding rectangle of the painted object.

Remarks

Write a CustomDrawBackground event handler to perform custom painting of the control’s background. Set the CustomDrawObjectEventArgs.Handled property of the event parameter to true to disable default background painting. Other event parameters provide you with all the necessary information to perform background painting.

Group captions and client areas occupy the entire control’s area in certain paint styles. Writing a CustomDrawBackground event has no impact in such a case.

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 code below handles the NavBarControl.CustomDrawBackground event to fill the background with a linear gradient brush.

csharp
using System.Drawing;

private void navBarControl1_CustomDrawBackground(object sender, CustomDrawObjectEventArgs e) {
    // Get the background bounds.
    Rectangle rect = e.RealBounds;

    // Get a gradient brush and fill the background. 
    Brush backBrush = e.Cache.GetGradientBrush(rect, Color.Pink, Color.LightSkyBlue, LinearGradientMode.Horizontal);
    e.Cache.FillRectangle(backBrush, rect);

    // Prevent the default paint algorithm from being invoked.
    e.Handled = true;
}
vb
Imports System.Drawing

Private Sub NavBarControl1_CustomDrawBackground(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs) _
  Handles NavBarControl1.CustomDrawBackground
    ' Get the background bounds.
    Dim rect As Rectangle = e.RealBounds

    ' Get a gradient brush and fill the background. 
    Dim backBrush As Brush = e.Cache.GetGradientBrush(rect, Color.Pink, Color.LightSkyBlue, LinearGradientMode.Horizontal)
    e.Cache.FillRectangle(backBrush, rect)

    ' Prevent the default paint algorithm from being invoked.
    e.Handled = True
End Sub

See Also

CustomDrawGroupClientBackground

CustomDrawGroupClientForeground

CustomDrawGroupCaption

CustomDrawLink

CustomDrawHint

NavBarControl Class

NavBarControl Members

DevExpress.XtraNavBar Namespace