This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
ZoomTrackBarWithMiddleSnap.vb
125 lines (105 loc) · 3.26 KB
/
ZoomTrackBarWithMiddleSnap.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
114
115
116
117
118
119
120
121
122
123
124
125
Imports Microsoft.VisualBasic
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Drawing
Imports DevExpress.XtraEditors.Registrator
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraEditors.ViewInfo
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Namespace ZoomTrackBarControl_MiddleValue
<UserRepositoryItem("Register")> _
Public Class CustomRepositoryItem
Inherits RepositoryItemZoomTrackBar
Shared Sub New()
Register()
End Sub
Public Sub New()
End Sub
Friend Const EditorName As String = "CustomZoomTrackBar"
Public Shared Sub Register()
EditorRegistrationInfo.Default.Editors.Add(New EditorClassInfo(EditorName, GetType(CustomZoomTrackBar), GetType(CustomRepositoryItem), GetType(CustomViewInfo), New ZoomTrackBarPainter(), Nothing))
End Sub
Public Overrides ReadOnly Property EditorTypeName() As String
Get
Return EditorName
End Get
End Property
Private _SnapToMiddleValue As Boolean
Public Property SnapToMiddleValue() As Boolean
Get
Return _SnapToMiddleValue
End Get
Set(ByVal value As Boolean)
_SnapToMiddleValue = value
End Set
End Property
Private _MiddleDistance As Integer
Public Property MiddleDistance() As Integer
Get
If _MiddleDistance > 100 OrElse _MiddleDistance <= 0 Then
_MiddleDistance = 10
End If
Return _MiddleDistance
End Get
Set(ByVal value As Integer)
_MiddleDistance = value
End Set
End Property
Public Overrides Sub Assign(ByVal item As RepositoryItem)
MyBase.Assign(item)
BeginUpdate()
Try
MyBase.Assign(item)
Dim source As CustomRepositoryItem = TryCast(item, CustomRepositoryItem)
If source Is Nothing Then
Return
End If
SnapToMiddleValue = source.SnapToMiddleValue
MiddleDistance = source.MiddleDistance
Finally
EndUpdate()
End Try
End Sub
End Class
<ToolboxItem(True)> _
Public Class CustomZoomTrackBar
Inherits ZoomTrackBarControl
Shared Sub New()
CustomRepositoryItem.Register()
End Sub
Public Sub New()
End Sub
Public Overrides ReadOnly Property EditorTypeName() As String
Get
Return CustomRepositoryItem.EditorName
End Get
End Property
<DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public Shadows ReadOnly Property Properties() As CustomRepositoryItem
Get
Return TryCast(MyBase.Properties, CustomRepositoryItem)
End Get
End Property
End Class
Public Class CustomViewInfo
Inherits ZoomTrackBarViewInfo
Public Sub New(ByVal item As RepositoryItem)
MyBase.New(item)
End Sub
Public Overrides Function ValueFromPoint(ByVal p As Point) As Integer
Dim customItem As CustomRepositoryItem = CType(Me.Item, CustomRepositoryItem)
Dim middle As Integer = If((customItem.AllowUseMiddleValue), customItem.Middle, (customItem.Minimum + customItem.Maximum) / 2)
Dim value As Integer = MyBase.ValueFromPoint(p)
Dim middleDistance As Integer = (customItem.Minimum + customItem.Maximum) / customItem.MiddleDistance
If value >= middle - middleDistance AndAlso value <= middle + middleDistance Then
Return middle
End If
Return value
End Function
End Class
End Namespace