Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel
<CLSCompliant(True), DesignTimeVisible(False)> _
Public Class ScrollBar
Protected intMax As Integer
Protected intMin As Integer
Protected intStep As Single
Protected intSmallStep As Single
Protected intValue As Single
Protected Sub on_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.intStep = 20
Me.intSmallStep = 5
Me.intMax = 100
Me.intMin = 0
SetMidButtonLocation()
End Sub
Public Property Maximum() As Integer
Get
Return Me.intMax
End Get
Set(ByVal value As Integer)
Me.intMax = value
End Set
End Property
Public Property Minimum() As Integer
Get
Return Me.intMin
End Get
Set(ByVal value As Integer)
Me.intMin = value
End Set
End Property
<DefaultValue(20)> _
Public Property LargeChange() As Single
Get
Return Me.intStep
End Get
Set(ByVal value As Single)
If value > 0 Then
If Me.intStep <> value Then
Me.intStep = value
End If
Else
Throw New Exception("Step muts be greater than zero")
End If
End Set
End Property
Public Property Value() As Single
Get
Return Me.intValue
End Get
Set(ByVal value2 As Single)
If value2 >= Me.intMin AndAlso value2 <= Me.intMax Then
Me.intValue = value2
ElseIf value2 < Me.intMin Then
value2 = Me.intMin
Else 'If value2 > Me.intMax Then
value2 = Me.intMax
End If
End Set
End Property
'public overrides property
<DefaultValue(5)> _
Public Property SmallChange() As Single
Get
Return Me.intSmallStep
End Get
Set(ByVal value As Single)
If value > 0 Then
If Me.intSmallStep <> value Then
Me.intSmallStep = value
End If
Else
Throw New Exception("SmallStep muts be greater than zero")
End If
End Set
End Property
Protected Overridable ReadOnly Property ScrollAreaRange() As Integer
Get
Return 0
End Get
End Property
Public Sub Increment()
Dim p As Integer
p = Me.intValue
If Me.intValue < Me.intMax Then
Me.intValue += Me.intStep
End If
If Me.intValue > Me.intMax Then
Me.intValue = Me.intMax
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.Last, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.LargeIncrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
End If
End Sub
Public Sub SmallIncrement()
Dim p As Integer
p = Me.intValue
If Me.intValue < Me.intMax Then
Me.intValue += Me.intSmallStep
End If
If Me.intValue > Me.intMax Then
Me.intValue = Me.intMax
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.Last, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.SmallIncrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
End If
End Sub
Public Sub SmallDecrement()
Dim p As Integer
p = Me.intValue
If Me.intValue > Me.intMin Then
Me.intValue -= Me.intSmallStep
End If
If Me.intValue < Me.intMin Then
Me.intValue = Me.intMin
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.First, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.SmallDecrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
End If
End Sub
Public Sub Decrement()
Dim p As Integer
p = Me.intValue
If Me.intValue > Me.intMin Then
Me.intValue -= Me.intStep
End If
If Me.intValue < Me.intMin Then
Me.intValue = Me.intMin
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.First, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.LargeDecrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
End If
End Sub
'Public Sub Reset()
' Me.intValue = Me.intMin
'End Sub
Protected Overridable Sub Redraw(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
ControlPaint.DrawBorder(e.Graphics, New Rectangle(0, 0, Me.Width, Me.Height), Me.ForeColor, ButtonBorderStyle.Inset)
End Sub
Protected Overridable Sub SetMidButtonLocation()
End Sub
Protected Sub On_MouseScroll(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyClass.MouseWheel
Dim p As Integer
p = Me.intValue
Me.intValue -= e.Delta * Me.intStep / 100
If Me.intValue < Me.intMin Then
Me.intValue = Me.intMin
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.First, Me.intValue, p, ScrollOrientation.VerticalScroll))
ElseIf Me.intValue > Me.intMax Then
Me.intValue = Me.intMax
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.Last, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
If e.Delta > 0 Then
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.LargeDecrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
Else
MyBase.OnScroll(New ScrollEventArgs(ScrollEventType.LargeIncrement, Me.intValue, p, ScrollOrientation.VerticalScroll))
End If
End If
SetMidButtonLocation()
End Sub
End Class