在默认情况下,使用特定绘制程序类的方法来绘制 XtraTreeList 控件的元素。 可以创建此绘制程序类的子类来重写特定元素的默认绘制。
TreeList 的绘制程序
TreeList 的绘制程序是实现了 ITreeListPaintHelper 接口 (下面的小节描述了此接口) 的对象。 要创建自定义绘制程序,则需要创建一个实现了 ITreeListPaintHelper 接口的类。 或者可以从 TreeList 的默认绘制程序 —— DevExpress.XtraTreeList.Painter.TreeListPaintHelper 类派生,从而创建自定义绘制程序类。
要使用自定义绘制程序类,则把它的一个实例指派到 TreeList.Painter 对象的 DefaultPainter 属性。 此属性引用绘制程序类的实例,此实例被用于绘制 TreeList 的元素。 最初,此属性引用一个 TreeListPaintHelper 对象。
ITreeListPaintHelper 接口
树状列表绘制帮助器必须支持 ITreeListPaintHelper 接口。 此接口声明了绘制特定类型元素的方法。 下面的代码是此接口的声明。
public interface ITreeListPaintHelper {
void DrawOpenCloseButton(CustomDrawNodeButtonEventArgs e);
void DrawColumn(CustomDrawColumnHeaderEventArgs e);
void DrawNodePreview(CustomDrawNodePreviewEventArgs e);
void DrawNodeSelectImage(CustomDrawNodeImagesEventArgs e);
void DrawNodeStateImage(CustomDrawNodeImagesEventArgs e);
void DrawIndicator(CustomDrawNodeIndicatorEventArgs e);
void DrawFooterBackGround(CustomDrawEventArgs e);
void DrawRowFooterCell(CustomDrawRowFooterCellEventArgs e);
void DrawFooterCell(CustomDrawFooterCellEventArgs e);
void DrawNodeCell(CustomDrawNodeCellEventArgs e);
}
下表列出了此接口的方法,提供了每个方法的简要说明,并且列出了可以用于代替它的自定义绘制事件。
示例
下面的代码创建了一个简单的绘制帮助器,它派生于标准的 TreeListPaintHelper 类。 DrawFooterBackGround 方法被重写,以便实现自定义绘制 汇总脚注。
下面的插图展示了在运行代码之前和之后的 XtraTreeList 控件。

C# | ![]() |
---|---|
using DevExpress.Utils; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Painter; using System.Drawing.Drawing2D; // ... public class SimplePaintHelper : TreeListPaintHelper { internal SimplePaintHelper(ImageList il_Indicator) : base(il_Indicator) {} public override void DrawFooterBackGround(CustomDrawEventArgs e) { LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.FromArgb(244, 210, 227), Color.FromArgb(207, 196, 230), LinearGradientMode.Vertical); e.Graphics.FillRectangle(brush, e.Bounds); } } //... // Use the painter: treeList1.Painter.DefaultPaintHelper = new SimplePaintHelper(treeList1.Painter.IndicatorImages); |
Visual Basic | ![]() |
---|---|
Imports DevExpress.Utils Imports DevExpress.XtraTreeList Imports DevExpress.XtraTreeList.Painter Imports System.Drawing.Drawing2D ' ... Public Class SimplePaintHelper Inherits TreeListPaintHelper Friend Sub New(ByVal il_Indicator As ImageList) MyBase.New(il_Indicator) End Sub Public Overrides Sub DrawFooterBackGround(ByVal e As CustomDrawEventArgs) Dim Brush As New LinearGradientBrush(e.Bounds, Color.FromArgb(244, 210, 227), Color.FromArgb(207, 196, 230), LinearGradientMode.Vertical) e.Graphics.FillRectangle(Brush, e.Bounds) End Sub End Class '... ' Use the painter: TreeList1.Painter.DefaultPaintHelper = New SimplePaintHelper(TreeList1.Painter.IndicatorImages) |