TreeList.CustomDrawNodeButton Event

Gives you the ability to perform custom painting of expand buttons.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

Declaration

[DXCategory("CustomDraw")]
public event CustomDrawNodeButtonEventHandler CustomDrawNodeButton
<DXCategory("CustomDraw")>
Public Event CustomDrawNodeButton As CustomDrawNodeButtonEventHandler

Event Data

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

Property Description
AllowDrawBackground Gets or sets whether to draw a background that detaches the button from the tree hierarchy lines.
Appearance Gets the painted element's appearance settings. Inherited from CustomDrawEventArgs.
Bounds Gets the painted element's bounding rectangle. Inherited from CustomDrawEventArgs.
Cache Gets an object specifying the storage for the most used pens, fonts and brushes. Inherited from CustomDrawEventArgs.
Expanded Gets a value indicating whether the painted button's corresponding node is expanded.
Graphics Gets an object used to paint. 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.
IsRightToLeft Gets a value indicating whether the TreeList's elements are aligned to support locales using right-to-left fonts. Inherited from CustomDrawEventArgs.
ObjectArgs Gets an object containing information about the painted element. Inherited from CustomDrawEventArgs.
Painter Gets the painter object that provides the default element's painting mechanism. Inherited from CustomDrawEventArgs.

Remarks

Expand buttons are used to expand/collapse nodes which have child nodes. Handle the CustomDrawNodeButton event to custom paint expand buttons.

The event's parameters provide all the information needed to perform node button painting. The CustomDrawNodeButtonEventArgs.Expanded property allows you to determine whether the painted button corresponds to the expanded or collapsed state of a node.

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.

Examples

The following sample code handles the TreeList.CustomDrawNodeButton event. It is used to perform custom painting of buttons used to expand/collapse nodes.

The image below displays the result of sample code execution.

CustomDraw - NodeButton

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

private void treeList1_CustomDrawNodeButton(object sender, CustomDrawNodeButtonEventArgs e) {
    Rectangle rect = Rectangle.Inflate(e.Bounds, 0, -2);

    // painting background
    Brush backBrush = e.Cache.GetGradientBrush(rect, Color.Blue, Color.LightSkyBlue,
      LinearGradientMode.ForwardDiagonal);

    e.Cache.FillRectangle(backBrush, rect);
    // painting borders
    e.Cache.DrawRectangle(e.Cache.GetPen(Color.LightGray), rect);

    // determining the character to display
    string displayCharacter = e.Expanded ? "-" : "+";
    // formatting the output character
    StringFormat outCharacterFormat = e.Appearance.GetStringFormat();
    outCharacterFormat.Alignment = StringAlignment.Center;
    outCharacterFormat.LineAlignment = StringAlignment.Center;

    // painting the character
    e.Appearance.FontSizeDelta = -2;
    e.Appearance.FontStyleDelta = FontStyle.Bold;
    e.Cache.DrawString(displayCharacter, e.Appearance.Font, 
        e.Cache.GetSolidBrush(Color.White), rect, outCharacterFormat);

    // prohibiting default painting
    e.Handled = true;
}
See Also