Click here to Skip to main content
15,892,746 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 Basics
Imports MidRange
Imports IMidRange
Imports GraphicsObjects




Public Class BVColorComboBox
    Inherits BVCtl.BVComboBox

#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()

    End Sub

    'Form reemplaza a Dispose para limpiar la lista de componentes.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            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.IContainer

    '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.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region

    Protected Shadows intSelectedItem As ComboBoxItemColor


    Protected Overrides Sub Initialize()
        hTbl = New BVHashTable
        AList = New BVArrayList

        intBrushCell = New System.Drawing.SolidBrush(Color.White)
        ExpandedAreaHeight = 100

        Dim i As Integer
        Dim Itm As ComboBoxItemColor
        Dim KC() As String
        Dim t As Type

        'For Each clr As Color In Color
        t = GetType(KnownColor)
        KC = [Enum].GetNames(t)
        'Itm.
        AList.Capacity = KC.GetUpperBound(0) + 1
        For i = 0 To KC.GetUpperBound(0)
            Itm = New ComboBoxItemColor(Me, KC(i))
            'Itm.Height = Me.Height
            'hTbl.Add(KC(i), Color.FromName(KC(i)))
            Add(Itm)
        Next

        vScrollBar_Scroll()
        AddHandler MyBase.Paint, AddressOf Redraw
    End Sub

#Region "Properties"

    Public Property SelectedColor() As Color
        Get
            If Me.intSelectedItem Is Nothing Then
                Return Color.Empty
            Else
                Return Me.intSelectedItem.Color
            End If
        End Get
        Set(ByVal Value As Color)
            Dim kC As KnownColor

            kC = Value.ToKnownColor 'KnownColor.fr()
            If kC = 0 Then
                Me.RaiseSendMessage(Me, New MessageEventArgs("This Color is UnKnown", MessageEventArgs.EMessageType.Warning))
            Else
                SelectedColorName = kC
            End If
            'color.isto
        End Set
    End Property

    Public Property SelectedColorName() As String
        Get
            If intSelectedItem Is Nothing Then
                Return "UnknownColor"
            Else
                Return Me.intSelectedItem.ColorName
            End If
        End Get
        Set(ByVal Value As String)
            Dim m As ComboBoxItemColor

            m = FindColorByName(Value)
            If Not m Is Nothing Then
                Me.intSelectedItem = m
                Me.Text = m.ColorName
            Else
                Me.RaiseSendMessage(Me, New MessageEventArgs("Color not found", MessageEventArgs.EMessageType.Eerror))
            End If
        End Set
    End Property

#End Region

#Region "private methods"

    Protected Function FindColorByName(ByVal colorName As String) As ComboBoxItemColor
        Dim i As Integer

        For i = 0 To AList.Count - 1
            If CType(AList(i), ComboBoxItemColor).ColorName = colorName Then
                Return Alist(i)
            End If
        Next
        Return Nothing
    End Function

    Private Shadows Sub Add(ByVal Itm As ComboBoxItemColor)
        AList.Add(Itm)
        AddHandler Itm.OnSelected, AddressOf On_ItemSelected
    End Sub

#End Region

    Protected Overrides Sub Redraw(ByVal sender As Object, ByVal P As PaintEventArgs)
        P.Graphics.FillRectangle(Me.intBrushCell, New Rectangle(0, 0, Me.Width - Me.BvBtnExpand.Width, Me.Height))

        If intIsExpanded Then
            Dim i As Integer
            Dim itm As ComboBoxItem

            P.Graphics.Clip = New Region(New Rectangle(0, Me.BvBtnExpand.Height + 1, Me.Width, Me.Height))
            For i = 0 To AList.Count - 1
                If CType(AList(i), ComboBoxItemColor).Y < Me.Height Then
                    If CType(AList(i), ComboBoxItemColor).Height > -Me.Height Then
                        CType(AList(i), ComboBoxItemColor).Redraw(sender, P)
                    End If
                End If
            Next
            'P.Graphics.Clear()
            P.Graphics.Clip = New Region(New Rectangle(0, 0, Me.Width, Me.Height))
        End If

        If Not intSelectedItem Is Nothing Then
            Dim yback As Integer
            yback = intSelectedItem.Y
            intSelectedItem.Y = 0
            intSelectedItem.Redraw(sender, P)
            intSelectedItem.Y = yback
        End If

        ControlPaint.DrawBorder3D(P.Graphics, 0, 0, Me.Width - Me.BvBtnExpand.Width, Me.Height, Border3DStyle.Flat)
        ControlPaint.DrawBorder3D(P.Graphics, 0, 0, Me.Width - Me.BvBtnExpand.Width, Me.BvBtnExpand.Height, Border3DStyle.Flat)
    End Sub

#Region "Item Position"

    Private 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
    Private ReadOnly Property GetInitialItemYPosition(ByVal index As Integer) As Integer
        Get
            If AList.Count = 0 Then
                Return Me.BvBtnExpand.Height
            End If
            If index < AList.Count And index >= 0 Then
                Return CType(AList(index), ComboBoxItemColor).Height * index
            Else
                Stop
            End If
        End Get
    End Property

    Private ReadOnly Property GetTotalItemHeight() As Integer
        Get
            If AList.Count > 0 Then
                Return (AList.Count - 1) * CType(AList(0), ComboBoxItemColor).Height
            Else
                Return Me.BvBtnExpand.Height
            End If
        End Get
    End Property

#End Region

#Region "Scrollbar Region"

    Protected Sub vScrollBar1_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs) Handles VScrollBar1.Scroll
        vScrollBar_Scroll()
    End Sub

    Protected Sub vScrollBar_Scroll()
        Dim i As Integer
        Dim itm As PropertyItemBase
        Dim o As Object

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

    Private Sub CheckScrollBar()
        If AList.Count > 0 Then
            Dim i As Integer
            Dim h As Integer

            h = GetTotalItemHeight()

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

#End Region

#Region "Events Managed"

    Protected Overrides Sub BvBtnExpand_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BvBtnExpand.Click
        intIsExpanded = True
        Me.Height = Me.BvBtnExpand.Height + ExpandedAreaHeight '100
        Me.VScrollBar1.Visible = True
    End Sub

    Protected Sub On_ItemSelected(ByVal sender As Object, ByVal e As EventArgs)
        Me.intSelectedItem = sender
        Me.Text = intSelectedItem.ColorName
        'raiseevent mybase.
        'mybase.ch
    End Sub


#End Region

End Class










Public Class ComboBoxItemColor
    Inherits ComboBoxItemBase

    Protected intNameColor As String

    Public Sub New(ByVal ParentControl As BVComboBox, ByVal ColorName As String)
        MyBase.New(ParentControl)

        intSelected = False
        intNameColor = ColorName

        intPen = New Pen(Color.LightGray)
        intBrush = New System.Drawing.SolidBrush(Color.FromName(ColorName))
        intBrushSelected = New System.Drawing.SolidBrush(Color.Green)
        intPen.Width = 1
        intBackColor = Color.White
        intForeColor = Color.Black
        intBrushText = New System.Drawing.SolidBrush(intForeColor)
        intFont = ParentControl.Font 'New System.Drawing.Font("Arial", 10)

    End Sub

#Region "Properties"

    Public ReadOnly Property ColorName() As String
        Get
            Return intNameColor
        End Get
    End Property

    Public ReadOnly Property Color() As Color
        Get
            Return Color.FromName(intNameColor)
        End Get
    End Property

#End Region

    Public Overrides Sub Redraw(ByVal sender As Object, ByVal p As PaintEventArgs)
        Dim s As SizeF

        p.Graphics.FillRectangle(intbrush, New Rectangle(3, Y + 3, Me.Height - 6, Me.Height - 6))
        p.Graphics.DrawRectangle(intpen, New Rectangle(3, Y + 3, Me.Height - 6, Me.Height - 6))

        s = p.Graphics.MeasureString(intNameColor, intFont)

        p.Graphics.DrawString(Me.intNameColor, intfont, Me.intBrushText, Me.Height, Y + 0.5 * Me.intRect.Height - 0.5 * s.Height)

    End Sub

#Region "Events Managed"

#Region "Mouse Events"

    Public Sub On_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles intParentControl.MouseDown
        If intRect.Contains(e.X, e.Y) Then
            If e.Y > CType(Me.intParentControl, BVColorComboBox).MainArea.Height Then
                If Not intSelected Then
                    Me.intSelected = True
                    RaiseSelected(Me, New EventArgs)
                    Me.intParentControl.Refresh()
                End If
            End If
        Else
            intSelected = False
        End If
    End Sub

#End Region

#End Region


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