Back to Devexpress

TreeList.CustomDrawNodePreview Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-2c2a8590.md

latest7.6 KB
Original Source

TreeList.CustomDrawNodePreview Event

Allows you to custom paint preview sections.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
[DXCategory("CustomDraw")]
public event CustomDrawNodePreviewEventHandler CustomDrawNodePreview
vb
<DXCategory("CustomDraw")>
Public Event CustomDrawNodePreview As CustomDrawNodePreviewEventHandler

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings.
BoundsGets the painted element’s bounding rectangle. Inherited from CustomDrawEventArgs.
CacheGets an object specifying the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
GraphicsGets an object used to paint. Inherited from CustomDrawEventArgs.
HandledGets or sets a value specifying whether an event was handled and that the default element painting is therefore not required. Inherited from CustomDrawEventArgs.
IsRightToLeftGets a value indicating whether the TreeList’s elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs.
ObjectArgsGets an object containing information about the painted element. Inherited from CustomDrawEventArgs.
PainterGets the painter object that provides the default element’s painting mechanism. Inherited from CustomDrawEventArgs.
PreviewTextGets or sets the painted preview section’s text.
PreviewTextBoundsGets the content bounds of the preview section.

The event data class exposes the following methods:

MethodDescription
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

See the Custom Draw Scenarios topic 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 sample code handles the TreeList.CustomDrawNodePreview event. It is used to perform custom painting of preview sections.

The image below displays the result of sample code execution.

csharp
using System.Drawing;
using System.Drawing.Drawing2D;
using DevExpress.XtraTreeList

private void treeList1_CustomDrawNodePreview(object sender, CustomDrawNodePreviewEventArgs e) {
    // filling background with a linear gradient brush
    Brush backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.LightGoldenrodYellow, Color.Cornsilk, LinearGradientMode.Vertical);
    e.Cache.FillRectangle(backBrush, e.Bounds);
    // painting the preview string
    e.Appearance.FontStyleDelta = FontStyle.Italic;
    e.Cache.DrawString(e.PreviewText, e.Appearance.Font, Brushes.Maroon, e.Bounds, e.Appearance.GetStringFormat());
    // prohibiting default painting
    e.Handled = true;
}
vb
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports DevExpress.XtraTreeList

Private Sub TreeList1_CustomDrawNodePreview(sender As Object, e As DevExpress.XtraTreeList.CustomDrawNodePreviewEventArgs) Handles TreeList1.CustomDrawNodePreview
    ' filling background with a linear gradient brush
    Dim backBrush = e.Cache.GetGradientBrush(e.Bounds, Color.LightGoldenrodYellow, Color.Cornsilk, LinearGradientMode.Vertical)
    e.Cache.FillRectangle(backBrush, e.Bounds)
    ' painting the preview string
    e.Appearance.FontStyleDelta = FontStyle.Italic
    e.Cache.DrawString(e.PreviewText, e.Appearance.Font, Brushes.Maroon, e.Bounds, e.Appearance.GetStringFormat())
    ' prohibiting default painting
    e.Handled = True
End Sub

See Also

CustomDrawNodeCell

CustomDrawNodeIndicator

CustomDrawRowFooter

CustomDrawRowFooterCell

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace