Back to Devexpress

TreeList.CustomDrawNodeImages Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-d837537a.md

latest8.8 KB
Original Source

TreeList.CustomDrawNodeImages Event

Provides access to a GDI+/DirectX drawing surface and allows you to draw node icons manually.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

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

Event Data

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

PropertyDescription
AppearanceGets the painted element’s appearance settings. Inherited from CustomDrawEventArgs.
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.
SelectImageIndexGets or sets the index of the image displayed within the painted node when it is focused.
SelectImageLocationGets the location of the select image’s top-left corner.
SelectRectGets the bounding rectangle of the select image.
StateImageIndexGets or sets the index of the state image displayed within the node.
StateImageLocationGets the location of the state image’s top-left corner.
StateRectGets the bounding rectangle of the state image.

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

Nodes can display the following icons:

  • Select Image - two icons that automatically switch when a node gets / loses the focus.
  • State Image - any custom icon.

Draw Node Images

The TreeList.CustomDrawNodeImages event provides access to a GDI+/DirectX drawing surface and allows you to draw node icons manually.

See Custom Draw Scenarios for more information on how to use a drawing surface.

Note

The CustomDrawNodeImages event does not occur if a node does not display the image(s) and the ViewStyle property is set to TreeListViewStyle.InCell.

The WXI skin activates the InCell (TreeView) style by default.

Custom Draw Event for In-Cell Images

The RowImagesShowMode property allows you to choose the location of node images. If a Tree List draws its node images inside cells and a cell has no image to display, the control does not allocate space for this image and the CustomDrawNodeImages event is never raised.

Example

The code below shows how to fill the background with a custom color and then draw the image on top.

csharp
private void TreeList_CustomDrawNodeImages(object sender, CustomDrawNodeImagesEventArgs e) {
    if (e.Node.Focused)
        e.Cache.FillRectangle(e.Cache.GetSolidBrush(Color.Orange), e.StateRect);
    e.DefaultDraw();
}
vb
Private Sub treeList1_CustomDrawNodeImages(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.CustomDrawNodeImagesEventArgs) _
    Handles treeList1.CustomDrawNodeImages
    If e.Node.Focused Then
        e.Cache.FillRectangle(e.Cache.GetSolidBrush(Color.Orange), e.StateRect)
    End If
    e.DefaultDraw()
End Sub

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.

See Also

Node Image

ImageIndexFieldName

ImageIndex

SelectImageIndex

StateImageIndex

GetSelectImage

GetStateImage

SelectImageList

StateImageList

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace