Click here to Skip to main content
15,896,063 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.4K   6.2K   171  
.NET Mathematical Framework
Imports System
Imports System.Reflection
Imports System.Reflection.Module
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Collections.Generic
Imports BV.Core
Imports MidRange
Imports IMidRange
Imports GraphicsObjects

'clase base de todos los controles que manejan Items y ScrollBarVertical
'por ejemplo el BVPropertyGrid y el ImageViewer
<CLSCompliant(True), DesignTimeVisible(False)> _
Public Class BVItmListBase
    Inherits System.Windows.Forms.UserControl
    Implements ISeleccionable

#Region " C�digo generado por el Dise�ador de Windows Forms "

    Public Sub New()
        MyBase.New()

        'El Dise�ador de Windows Forms requiere esta llamada.
        InitializeComponent()

        'Agregar cualquier inicializaci�n despu�s de la llamada a InitializeComponent()
        Initialize()
    End Sub

    'UserControl1 reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            RemoveHandler Seleccionable.Selected, AddressOf OnSomeSelected
            RemoveHandler VScrollBar1.Scroll, AddressOf vScrollBar1_Scroll
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Requerido por el Dise�ador de Windows Forms
    Private components As System.ComponentModel.Container

    'NOTA: el Dise�ador de Windows Forms requiere el siguiente procedimiento
    'Puede modificarse utilizando el Dise�ador de Windows Forms. 
    'No lo modifique con el editor de c�digo.
    Protected Friend WithEvents VScrollBar1 As BV.Controls.VScrollBar
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.VScrollBar1 = New BV.Controls.VScrollBar
        Me.SuspendLayout()
        '
        'VScrollBar1
        '
        Me.VScrollBar1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.VScrollBar1.LargeChange = 30
        Me.VScrollBar1.Location = New System.Drawing.Point(168, 0)
        Me.VScrollBar1.Name = "VScrollBar1"
        Me.VScrollBar1.Size = New System.Drawing.Size(16, 224)
        Me.VScrollBar1.SmallChange = 5
        Me.VScrollBar1.TabIndex = 0
        '
        'BVItmListBase
        '
        Me.Controls.Add(Me.VScrollBar1)
        Me.Name = "BVItmListBase"
        Me.Size = New System.Drawing.Size(184, 224)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Protected intBrush As SolidBrush
    Protected intBrushCell As SolidBrush
    Protected intBrushText As SolidBrush
    Protected intPen As Pen
    Protected intFont As Font
    Protected HTbl As BVHashTable
    Protected intDefaultItemSize As Size

    Protected intSelectedItm As Integer     '-1 para ninguno
    Protected intSelectObj As Seleccionable

    Public Event ItemFocused(ByVal sender As Object, ByVal e As ItmEventArgs)
    Public Event ItemSelected(ByVal sender As Object, ByVal e As ItmEventArgs)
    Public Event Selected(ByVal sender As Object, ByVal e As EventArgs)


#Region "Initialize"

    Protected Overridable Sub Initialize()
        intSelectedItm = -1
        intSelectObj = New Seleccionable
        intSelectObj.IsSelected = False

        HTbl = New BVHashTable

        SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.UserPaint, True)
        VScrollBar1.Visible = False

        intPen = New Pen(Color.LightGray)
        intBrushCell = New System.Drawing.SolidBrush(intPen.Color)
        intPen.Width = 1
        'BackColor = Color.White
        intBrush = New System.Drawing.SolidBrush(BackColor)
        intBrushText = New System.Drawing.SolidBrush(ForeColor)
        intFont = New System.Drawing.Font("Arial", 10)

        VScrollBar1.LargeChange = 20
        MyBase.AllowDrop = True

        AddHandler Seleccionable.Selected, AddressOf OnSomeSelected
        AddHandler VScrollBar1.Scroll, AddressOf vScrollBar1_Scroll
    End Sub

#End Region

    <Browsable(False)> _
    Public Overridable Property IsSelected() As Boolean Implements ISeleccionable.IsSelected
        Get
            Return intSelectObj.IsSelected
        End Get
        Set(ByVal Value As Boolean)
            intSelectObj.IsSelected = Value
        End Set
    End Property

    <Browsable(False)> _
    Public ReadOnly Property DefaultItemSize() As Size
        Get
            Return intDefaultItemSize
        End Get
    End Property

#Region "Private properties"

    'Devuelve la Posicion Y del Item deseado, indicado con Index
    Protected Overridable ReadOnly Property GetCurrentItemYPosition(ByVal index As Integer) As Integer
        Get
            Return GetInitialItemYPosition(index) - (GetTotalItemHeight() - Me.Height) * 0.01F * VScrollBar1.Value
        End Get
    End Property

    'retorna la posicion Y de el thumbnail indicado
    Protected Overridable ReadOnly Property GetInitialItemYPosition(ByVal index As Integer) As Integer
        Get
            If HTbl.Count = 0 Then
                Return 0
            End If
            If index <= HTbl.Count And index >= 0 Then
                Dim i, h As Integer

                h = 0
                For i = 0 To index - 1
                    h = CType(HTbl(i), ItemBase).Height + h
                Next
                Return h
            Else
                Stop
            End If
        End Get
    End Property

    Protected Overridable ReadOnly Property GetTotalItemHeight() As Integer
        Get
            Dim i, h As Integer
            h = 0
            For i = 0 To HTbl.Count - 1
                'h = CType(Me.hTbl.Item(HTbl(i)), ItemBase).Height + h
                h = CType(HTbl(i), ItemBase).Height + h
            Next
            Return h
        End Get
    End Property

#End Region

#Region "Private Methods"

    Protected Overridable Function CheckScrollBar() As Boolean
        If HTbl.Count > 0 Then
            Dim h As Integer

            h = GetTotalItemHeight()

            If Me.Height <= h Then
                If VScrollBar1.Visible = False Then
                    Me.VScrollBar1.Visible = True
                    VScrollBar1.Value = 0
                    CheckScrollBar = True
                End If
            Else
                Me.VScrollBar1.Visible = False
                VScrollBar1.Value = 0
                CheckScrollBar = False
            End If
        End If
    End Function

    Protected Overridable Sub UpdatePositions()
        Dim i As Integer

        For i = 0 To HTbl.Count - 1
            CType(HTbl(i), ItemBase).Y = Me.GetCurrentItemYPosition(i)
        Next
        Me.Refresh()
    End Sub

#End Region

#Region "Event Manage"

    'Protected Overrides Sub On_VScroll(ByVal sender As Object, ByVal e As ScrollEventArgs)

    'End Sub

    Protected Overridable Sub vScrollBar1_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs)
        If VScrollBar1.Value > 80 Then
            VScrollBar1.LargeChange = 5
        ElseIf VScrollBar1.Value > 60 Then
            VScrollBar1.LargeChange = 10
            'ElseIf VScrollBar1.Value > 40 Then
            '    VScrollBar1.LargeChange = 30
        Else
            VScrollBar1.LargeChange = 30
        End If

        If e.Type = ScrollEventType.LargeDecrement Or e.Type = ScrollEventType.LargeIncrement _
        Or e.Type = ScrollEventType.SmallDecrement Or e.Type = ScrollEventType.SmallIncrement _
        Or e.Type = ScrollEventType.ThumbTrack Then
            UpdatePositions()
            'Else
            'e.Type=
            'Exit Sub
        End If
    End Sub

#End Region

#Region "Raise Methods"

    Protected Overridable Sub RaiseSendMessage(ByVal sender As Object, ByVal e As MessageEventArgs)
        MessageManager.Send(sender, e)
    End Sub

    Protected Overridable Sub RaiseItemFocused(ByVal sender As Object, ByVal e As ItmEventArgs)
        RaiseEvent ItemFocused(sender, e)
    End Sub

    Protected Overridable Sub RaiseItemSelected(ByVal sender As Object, ByVal e As ItmEventArgs)
        RaiseEvent ItemSelected(sender, e)
    End Sub

    Protected Overridable Sub RaiseSelected(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent Selected(sender, e)
    End Sub

#End Region

#Region "Redraw-Refresh"

    Protected Overridable Sub Redraw(ByVal sender As Object, ByVal P As PaintEventArgs) 'Handles MyBase.Paint
        Dim i As Integer

        P.Graphics.FillRectangle(intBrush, New System.Drawing.Rectangle(0, 0, Me.Width, Me.Height))

        For i = 0 To HTbl.Count - 1
            CType(HTbl(i), ItemBase).Redraw(sender, P)
        Next
    End Sub

    Private Delegate Sub simpleDelegate()
    Protected isBusy As Boolean
    Dim DelPtr As simpleDelegate

    Public Overrides Sub Refresh()
        If Me.InvokeRequired Then
            DelPtr = New simpleDelegate(AddressOf Refresh)
            Me.Invoke(DelPtr)
        Else
            If Not isBusy Then
                MyBase.Refresh()
            End If
        End If
    End Sub

#End Region


    Protected Overridable Sub OnSomeSelected(ByVal sender As Object, ByVal e As System.EventArgs) Implements ISeleccionable.OnSomeSelected
        If Not sender Is Me Then
            Me.intSelectObj.IsSelected = False
        End If
    End Sub


    'Protected Overrides  onit

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