how to show node buttons in treelist in devexpress c# code example

Example: how to show node buttons in treelist in devexpress c#

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;
}