Click here to Skip to main content
15,886,560 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
Imports System.Reflection
Imports System.Reflection.Module
Imports System.Drawing
Imports System.Windows.Forms
Imports ggCoreLib
Imports MidRange
Imports IMidRange
Imports GraphicsObjects



<CLSCompliant(True)> _
Public MustInherit Class ItemBase
    Implements IGraphics
    Implements ISeleccionable

    Protected intBrush As SolidBrush
    Protected intBrushSelected As SolidBrush
    Protected intBrushText As SolidBrush
    Protected intPen As Pen
    Protected intFont As Font
    Protected intBackColor As Color
    Protected intForeColor As Color

    Protected WithEvents intParentControl As Control
    Protected intRect As System.Drawing.Rectangle      'rectangulo que abarca todo el Item
    Protected intSelectObj As Seleccionable

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

    Public Sub New(ByVal ParentControl As Control)
        intParentControl = ParentControl

        intSelectObj = New Seleccionable
        intSelectObj.IsSelected = False

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

        AddHandler Seleccionable.Selected, AddressOf OnSomeSelected
    End Sub

#Region "Properties"

    Public Property IsSelected() As Boolean Implements ISeleccionable.IsSelected
        Get
            Return Me.intSelectObj.IsSelected
        End Get
        Set(ByVal Value As Boolean)
            intSelectObj.IsSelected = Value
        End Set
    End Property

#End Region

#Region "Size & Location"

    Public Overridable ReadOnly Property Height() As Integer
        Get
            Return Me.intRect.Height
        End Get
    End Property

    Public Overridable ReadOnly Property Width() As Integer
        Get
            Return Me.intRect.Width
        End Get
    End Property

    Public Overridable Property Rectangle() As System.Drawing.Rectangle
        Get
            Return intRect
        End Get
        Set(ByVal Value As System.Drawing.Rectangle)
            intRect = Value
        End Set
    End Property

    Public Overridable Property Location() As Point
        Get
            Return intRect.Location
        End Get
        Set(ByVal Value As Point)
            intRect.Location = Value
        End Set
    End Property

    Public Overridable Property Y() As Integer
        Get
            Return Me.intRect.Y
        End Get
        Set(ByVal Value As Integer)
            intRect.Y = Value
        End Set
    End Property

    Public Overridable Property X() As Integer
        Get
            Return Me.intRect.X
        End Get
        Set(ByVal Value As Integer)
            intRect.X = Value
        End Set
    End Property

#End Region

    Public MustOverride Sub Redraw(ByVal sender As Object, ByVal p As PaintEventArgs) Implements IGraphicsBase.Redraw

    Public Sub Refresh() Implements IGraphics.Refresh
        intParentControl.Refresh()
    End Sub

    Public Overridable Function Contains(ByVal x As Integer, ByVal y As Integer) As Boolean
        Return intRect.Contains(x, y)
    End Function

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

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

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

    Protected Overridable Sub On_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles intParentControl.MouseClick
        If intRect.Contains(e.X, e.Y) Then
            If Not intSelectObj.IsSelected Then
                intSelectObj.IsSelected = True
                Me.RaiseItemFocused(Me, New EventArgs)
                'Seleccionable.RaiseSelected(Me, New EventArgs)
            End If
        Else
            If intSelectObj.IsSelected Then
                intSelectObj.IsSelected = False
            End If
        End If
    End Sub

    Protected Overridable Sub On_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles intParentControl.MouseDoubleClick
        If intRect.Contains(e.X, e.Y) Then
            Seleccionable.RaiseSelected(Me, New EventArgs)
            Me.RaiseSelected(Me, New EventArgs)
        End If
    End Sub

    Public 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

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