Click here to Skip to main content
15,885,150 members
Articles / Programming Languages / Visual Basic

Mathemathics Framework

Rate me:
Please Sign up or sign in to vote.
4.76/5 (56 votes)
16 Sep 2008CPOL6 min read 75.3K   6.2K   171  
.NET Mathematical Framework
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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer Universidad Tecnológica Nacional
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions