-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.vb
69 lines (62 loc) · 2.43 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.ViewInfo
Imports DevExpress.XtraTreeList.Nodes
Namespace Q220534
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub OnTreeListCustomDrawNodeIndent(ByVal sender As Object, ByVal e As CustomDrawNodeIndentEventArgs) Handles treeList.CustomDrawNodeIndent
e.Handled = True
Dim tree As TreeList = DirectCast(sender, TreeList)
Dim groupLevelIndentRects As New Dictionary(Of Integer, Rectangle)()
CalcGroupLevelIndentRects(tree.ViewInfo, e.Node, e.Bounds, groupLevelIndentRects)
For Each kvp As KeyValuePair(Of Integer, Rectangle) In groupLevelIndentRects
e.Cache.FillRectangle(e.Cache.GetSolidBrush(GetColorByLevel(kvp.Key)), kvp.Value)
Next kvp
If e.Node.ParentNode Is Nothing Then
Dim linePen As Pen = e.Cache.GetPen(tree.ViewInfo.PaintAppearance.HorzLine.BackColor)
e.Cache.DrawLine(linePen, e.Bounds.Location, New Point(e.Bounds.Right, e.Bounds.Y))
End If
End Sub
Private Sub CalcGroupLevelIndentRects(ByVal viewInfo As TreeListViewInfo, ByVal currentNode As TreeListNode, ByVal bounds As Rectangle, ByVal rects As Dictionary(Of Integer, Rectangle))
If currentNode Is Nothing Then
Return
End If
If currentNode.HasChildren Then
rects.Add(currentNode.Level, New Rectangle(bounds.Right - viewInfo.RC.LevelWidth, bounds.Y, viewInfo.RC.LevelWidth, bounds.Height))
End If
bounds = New Rectangle(bounds.Location, New Size(bounds.Width - viewInfo.RC.LevelWidth, bounds.Height))
CalcGroupLevelIndentRects(viewInfo, currentNode.ParentNode, bounds, rects)
End Sub
Private Function GetColorByLevel(ByVal level As Integer) As Color
Select Case level
Case 0
Return Color.Red
Case 1
Return Color.Yellow
Case 2
Return Color.Green
Case Else
Return Color.Black
End Select
End Function
Private Sub OnTreeListNodeCellStyle(ByVal sender As Object, ByVal e As GetCustomNodeCellStyleEventArgs) Handles treeList.NodeCellStyle
If Not e.Node.HasChildren Then
Return
End If
e.Appearance.BackColor = GetColorByLevel(e.Node.Level)
End Sub
Private Sub OnFormLoad(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
treeList.ExpandAll()
End Sub
End Class
End Namespace