BandedGridView.CustomDrawBandHeader Event
Enables you to custom paint band headers.
Namespace: DevExpress.XtraGrid.Views.BandedGrid
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
[DXCategory("CustomDraw")]
public event BandHeaderCustomDrawEventHandler CustomDrawBandHeader
Event Data
The CustomDrawBandHeader event's data class is BandHeaderCustomDrawEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Appearance | Gets the painted element’s appearance settings. Inherited from CustomDrawEventArgs. |
Band | Gets the band whose header is to be painted. Returns null if an “empty band header” is currently being painted. |
Bounds | Returns a value specifying limits for the drawing area. Inherited from CustomDrawEventArgs. |
Cache | Provides methods to paint on drawing surfaces in GDI+ and DirectX modes. See DirectX hardware acceleration to learn more. Inherited from CustomDrawEventArgs. |
Graphics | A GDI+ drawing surface. Use the CustomDrawEventArgs.Cache property instead if you enable the DirectX hardware acceleration. Inherited from CustomDrawEventArgs. |
Handled | Gets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs. |
Info | Gets an object providing View information for the band header being painted. |
Painter | Gets the painter object that provides the default element painting mechanism. Inherited from CustomDrawObjectEventArgs. |
The event data class exposes the following methods:
Method | Description |
---|---|
DefaultDraw() | Performs default painting of an element. Inherited from CustomDrawEventArgs. |
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawEventArgs. |
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>) | Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawEventArgs. |
Remarks
The CustomDrawBandHeader event fires when a band header is about to be painted. See the Custom Painting Basics and Custom Painting Scenarios topics for information on using custom draw events.
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 following code handles the BandedGridView.CustomDrawBandHeader
event to paint band headers with a 3D effect in the pressed state.
private void bandedGridView1_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e) {
if (e.Band == null) return;
if (e.Info.State != ObjectState.Pressed) return;
using (Brush brushPressed = new LinearGradientBrush(e.Bounds, Color.WhiteSmoke, Color.Gray, LinearGradientMode.ForwardDiagonal)) {
Rectangle r = e.Bounds;
Draw3DBorder(e.Cache, r);
r.Inflate(-1, -1);
//Fill the background
e.Cache.FillRectangle(brushPressed, r);
//Draw a band glyph
foreach (DrawElementInfo info in e.Info.InnerElements) {
if (!info.Visible) continue;
GlyphElementInfoArgs glyphInfoArgs = info.ElementInfo as GlyphElementInfoArgs;
if (glyphInfoArgs == null) continue;
info.ElementInfo.OffsetContent(1, 1);
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
info.ElementInfo.OffsetContent(-1, -1);
break;
}
//Draw the band's caption with a shadowed effect
Rectangle textRect = e.Info.CaptionRect;
textRect.Offset(2, 2);
e.Appearance.DrawString(e.Cache, e.Info.Caption, textRect, Brushes.White);
textRect.Offset(-1, -1);
e.Appearance.DrawString(e.Cache, e.Info.Caption, textRect, Brushes.Black);
//Prevent default painting
e.Handled = true;
}
}
private void Draw3DBorder(GraphicsCache cache, Rectangle rect) {
//Draw a 3D border
BorderPainter painter = BorderHelper.GetPainter(DevExpress.XtraEditors.Controls.BorderStyles.Style3D);
AppearanceObject borderAppearance = new AppearanceObject();
borderAppearance.BorderColor = Color.DarkGray;
painter.DrawObject(new BorderObjectInfoArgs(cache, borderAppearance, rect));
}