This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
RangeList.vb
113 lines (98 loc) · 2.51 KB
/
RangeList.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Collections
Imports DevExpress.XtraEditors.Repository
Namespace CustomRangeTrackBarControl
Public Class RangeList
Private list As List(Of TrackBarRange)
Public Event ListChanged As EventHandler
Public Sub New()
list = New List(Of TrackBarRange)()
list.Add(New TrackBarRange())
End Sub
Public Sub New(ByVal _list As RangeList)
list = New List(Of TrackBarRange)()
Me.Assign(_list)
End Sub
Public Function GetValue(ByVal index As Integer) As TrackBarRange
Return list(index)
End Function
Public ReadOnly Property Count() As Integer
Get
Return list.Count
End Get
End Property
Private Function CheckAdd(ByVal range As TrackBarRange) As Boolean
For Each r As TrackBarRange In list
If range.Maximum >= r.Minimum Then
Return False
End If
Next r
Return True
End Function
Private Function CheckChange(ByVal index As Integer, ByVal range As TrackBarRange) As Boolean
Dim res As Boolean = True
For i As Integer = index + 1 To list.Count - 1
If range.Minimum <= list(i).Maximum Then
res = False
End If
Next i
For i As Integer = 0 To index - 1
If range.Maximum >= list(i).Minimum Then
res = False
End If
Next i
Return res
End Function
Private Sub OnListChanged()
RaiseEvent ListChanged(Me, New EventArgs())
End Sub
Public Sub Add(ByVal range As TrackBarRange)
If CheckAdd(range) Then
list.Add(range)
OnListChanged()
End If
End Sub
Public Sub ChangeValue(ByVal index As Integer, ByVal range As TrackBarRange)
If CheckChange(index, range) Then
list(index) = range
OnListChanged()
End If
End Sub
Public Function RemoveAt(ByVal index As Integer) As Boolean
If index >= list.Count AndAlso index > 0 Then
Return False
End If
list.RemoveAt(index)
OnListChanged()
Return True
End Function
Public Sub Remove(ByVal range As TrackBarRange)
Dim index As Integer = -1
For i As Integer = 0 To list.Count - 1
If list(i) = range Then
index = i
End If
Next i
list.Remove(range)
OnListChanged()
End Sub
Friend Sub Assign(ByVal newList As RangeList)
list.Clear()
For i As Integer = 0 To newList.Count - 1
list.Add(newList.GetValue(i))
Next i
End Sub
Public Sub Clear()
Dim i As Integer = 1
Do While i < list.Count
list.RemoveAt(i)
i += 1
Loop
OnListChanged()
End Sub
End Class
End Namespace