This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
DrawHelper.vb
75 lines (66 loc) · 2.85 KB
/
DrawHelper.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
70
71
72
73
74
75
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.ViewInfo
Imports DevExpress.XtraTreeList.Nodes
Imports System.Windows.Forms
Imports System.Drawing
Namespace TreeListDrawImage
Public Class DrawHelper
Private fTreeList As TreeList
Public Sub RegisterTreeList(ByVal treeList As TreeList)
Me.fTreeList = treeList
SubscribeEvents()
End Sub
Public Sub RegisterTreeList(ByVal treeList As TreeList, ByVal image As Image)
RegisterTreeList(treeList)
Me.Image = image
End Sub
Public Sub Unregister()
UnsubscribeEvents()
fTreeList = Nothing
End Sub
Public Property Image() As Image
Public Event ImageClick As EventHandler
Private Sub SubscribeEvents()
AddHandler fTreeList.CustomDrawNodeIndicator, AddressOf treeList1_CustomDrawNodeIndicator
AddHandler fTreeList.Click, AddressOf treeList1_Click
AddHandler fTreeList.MouseMove, AddressOf treeList1_MouseMove
End Sub
Private Sub UnsubscribeEvents()
RemoveHandler fTreeList.CustomDrawNodeIndicator, AddressOf treeList1_CustomDrawNodeIndicator
RemoveHandler fTreeList.Click, AddressOf treeList1_Click
RemoveHandler fTreeList.MouseMove, AddressOf treeList1_MouseMove
End Sub
Private Sub treeList1_CustomDrawNodeIndicator(ByVal sender As Object, ByVal e As CustomDrawNodeIndicatorEventArgs)
Dim tree As TreeList = TryCast(sender, TreeList)
Dim backBrush As Brush = tree.ViewInfo.PaintAppearance.Row.GetBackBrush(e.Cache)
e.Cache.FillRectangle(backBrush, e.Bounds)
If node Is e.Node Then
e.Cache.DrawImage(Image, e.Bounds.Location)
End If
e.Handled = True
End Sub
Private Sub treeList1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim tree As TreeList = TryCast(sender, TreeList)
Dim pt As Point = tree.PointToClient(Control.MousePosition)
Dim hitInfo = tree.CalcHitInfo(pt)
If hitInfo.HitInfoType = HitInfoType.RowIndicator Then
RaiseEvent ImageClick(Me, EventArgs.Empty)
End If
End Sub
Private node As TreeListNode
Private Sub treeList1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim tree As TreeList = TryCast(sender, TreeList)
Dim hitInfo = tree.CalcHitInfo(e.Location)
Dim currentNode As TreeListNode = hitInfo.Node
If currentNode IsNot node Then
tree.InvalidateNode(node)
node = currentNode
tree.InvalidateNode(node)
End If
End Sub
End Class
End Namespace