agLegend.vb

 Imports System.ComponentModel

Public Class agLegend
    Inherits System.ComponentModel.Component

#Region " Component Designer generated code "

    Public Sub New(ByVal Container As System.ComponentModel.IContainer)
        MyClass.New()

        'Required for Windows.Forms Class Composition Designer support
        Container.Add(Me)
    End Sub

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Component overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        If Not m_Items Is Nothing Then
            Dim XX As Integer
            For XX = 0 To UBound(m_Items)
                m_Items(XX).Dispose()
            Next
        End If
        m_CaptionFont.Dispose()
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Component Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Component Designer
    'It can be modified using the Component Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub

#End Region

#Region "Enumerations"
    Public Enum AGLegendModalStateConstants
        agShowModal = 0
        agShowModeless = 1
    End Enum
    Public Enum AGLegendShapesStyleConstants
        agShapedRectangle = 0
        agShapedCircle = 1
        agRectangle = 2
        agCircle = 3
    End Enum
    Public Enum AGLegendCaptionBackStyle
        agTransparent = 0
        agOpaque = 1
    End Enum
#End Region

#Region "Declarations"
    Private m_BackColor As Color = Color.White
    Private m_CaptionBackColor As Color = Color.White
    Private m_CaptionForeColor As Color = Color.Black
    Private m_CaptionText As String = String.Empty
    Private m_Moveable As Boolean = False
    Private m_Shadowed As Boolean = False
    Private m_FixedWidth As Integer = -1
    Private m_CaptionFont As Font = New Font("Microsoft Sans Serif", 8.25)
    Private m_ModalState As AGLegendModalStateConstants = AGLegendModalStateConstants.agShowModal
    Private m_ShapesStyle As AGLegendShapesStyleConstants = AGLegendShapesStyleConstants.agShapedRectangle
    Private m_CaptionBackStyle As AGLegendCaptionBackStyle = AGLegendCaptionBackStyle.agTransparent

    Private m_Items() As LegendItem
#End Region

#Region "Methods"
    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String, ByVal LegendColor As Color, ByVal LegendFont As Font, ByVal LegendForeColor As Color)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText, LegendColor, LegendFont, LegendForeColor)
    End Sub

    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String, ByVal LegendColor As Color, ByVal LegendForeColor As Color)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText, LegendColor, LegendForeColor)
    End Sub

    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String, ByVal LegendColor As Color, ByVal LegendFont As Font)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText, LegendColor, LegendFont)
    End Sub

    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String, ByVal LegendFont As Font)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText, LegendFont)
    End Sub

    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String, ByVal LegendColor As Color)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText, LegendColor)
    End Sub

    <Description("Adds new item to legend box items collection")> _
    Public Sub AddItem(ByVal LegendText As String)
        If m_Items Is Nothing Then
            ReDim m_Items(0)
        Else
            ReDim Preserve m_Items(UBound(m_Items) + 1)
        End If
        m_Items(UBound(m_Items)) = New LegendItem(LegendText)
    End Sub

    <Description("Resets legend box items collection")> _
    Public Sub Reset()
        Erase m_Items
    End Sub

    <Description("Resets legend box items collection and returns default properties values")> _
    Public Sub ResetAll()
        MyClass.Reset()
        m_BackColor = Color.White
        m_CaptionBackColor = Color.White
        m_CaptionForeColor = Color.Black
        m_CaptionText = String.Empty
        m_Moveable = False
        m_Shadowed = False
        m_FixedWidth = -1
        m_CaptionFont = New Font("Microsoft Sans Serif", 8.25)
        m_ModalState = AGLegendModalStateConstants.agShowModal
        m_ShapesStyle = AGLegendShapesStyleConstants.agShapedRectangle
        m_CaptionBackStyle = AGLegendCaptionBackStyle.agTransparent
    End Sub

    <Description("Shows legend window")> _
    Public Sub ShowLegend(ByVal X As Integer, ByVal Y As Integer, ByVal ctl As Control)
        Dim frm As frmLegend

        Try
            frm = New frmLegend(ctl.PointToScreen(New Point(X, Y)))
            frm.SetItems(Me)
            If m_ModalState = AGLegendModalStateConstants.agShowModeless Then
                frm.Show()
            Else
                frm.ShowDialog()
            End If
        Catch excp As Exception
            Throw excp
        End Try
    End Sub

    <Description("Shows legend window")> _
    Public Sub ShowLegend(ByVal pnt As Point, ByVal ctl As Control)
        Dim frm As frmLegend

        Try
            frm = New frmLegend(ctl.PointToScreen(pnt))
            frm.SetItems(Me)
            If m_ModalState = AGLegendModalStateConstants.agShowModeless Then
                frm.Show()
            Else
                frm.ShowDialog()
            End If
        Catch excp As Exception
            Throw excp
        End Try
    End Sub

    <Description("Shows legend window")> _
    Public Sub ShowLegend(ByVal X As Integer, ByVal Y As Integer)
        Dim frm As frmLegend

        Try
            frm = New frmLegend(New Point(X, Y))
            frm.SetItems(Me)
            If m_ModalState = AGLegendModalStateConstants.agShowModeless Then
                frm.Show()
            Else
                frm.ShowDialog()
            End If
        Catch excp As Exception
            Throw excp
        End Try
    End Sub

    <Description("Shows legend window")> _
    Public Sub ShowLegend(ByVal pnt As Point)
        Dim frm As frmLegend

        Try
            frm = New frmLegend(pnt)
            frm.SetItems(Me)
            If m_ModalState = AGLegendModalStateConstants.agShowModeless Then
                frm.Show()
            Else
                frm.ShowDialog()
            End If
        Catch excp As Exception
            Throw excp
        End Try
    End Sub
#End Region

#Region "Properties"
    Friend ReadOnly Property Items() As LegendItem()
        Get
            Return m_Items
        End Get
    End Property
    <Description("Returns/sets the back color of legend window.")> _
    Public Property BackColor() As Color
        Get
            Return m_BackColor
        End Get
        Set(ByVal Value As Color)
            m_BackColor = Value
        End Set
    End Property
    <Description("Returns/sets the back color of legend window's caption.")> _
    Public Property CaptionBackColor() As Color
        Get
            Return m_CaptionBackColor
        End Get
        Set(ByVal Value As Color)
            m_CaptionBackColor = Value
        End Set
    End Property
    <Description("The foreground color used to draw text on legend window's caption.")> _
    Public Property CaptionForeColor() As Color
        Get
            Return m_CaptionForeColor
        End Get
        Set(ByVal Value As Color)
            m_CaptionForeColor = Value
        End Set
    End Property
    <Description("Returns/sets the text drawn on legend window's caption.")> _
    Public Property CaptionText() As String
        Get
            Return m_CaptionText
        End Get
        Set(ByVal Value As String)
            m_CaptionText = Value
        End Set
    End Property
    <Description("Returns/sets the back style of legend window's caption.")> _
    Public Property CaptionBackStyle() As AGLegendCaptionBackStyle
        Get
            Return m_CaptionBackStyle
        End Get
        Set(ByVal Value As AGLegendCaptionBackStyle)
            m_CaptionBackStyle = Value
        End Set
    End Property
    <Description("Returns/sets the moveable state of legend window.")> _
    Public Property Moveable() As Boolean
        Get
            Return m_Moveable
        End Get
        Set(ByVal Value As Boolean)
            m_Moveable = Value
        End Set
    End Property
    <Description("Indicates whether shadow must be drawn behind legend window.")> _
    Public Property Shadowed() As Boolean
        Get
            Return m_Shadowed
        End Get
        Set(ByVal Value As Boolean)
            m_Shadowed = Value
        End Set
    End Property
    <Description("Returns/sets the font used to draw text on legend window's caption")> _
    Public Property CaptionFont() As Font
        Get
            Return m_CaptionFont
        End Get
        Set(ByVal Value As Font)
            m_CaptionFont = Value
        End Set
    End Property
    <Description("Returns/sets the fixed width of legend window.")> _
    Public Property FixedWidth() As Integer
        Get
            Return m_FixedWidth
        End Get
        Set(ByVal Value As Integer)
            m_FixedWidth = Value
        End Set
    End Property
    <Description("Returns/sets the modal state of legend window.")> _
     Public Property ModalState() As AGLegendModalStateConstants
        Get
            Return m_ModalState
        End Get
        Set(ByVal Value As AGLegendModalStateConstants)
            m_ModalState = Value
        End Set
    End Property
    <Description("Returns/sets the style of legend markers.")> _
    Property ShapesStyle() As AGLegendShapesStyleConstants
        Get
            Return m_ShapesStyle
        End Get
        Set(ByVal Value As AGLegendShapesStyleConstants)
            m_ShapesStyle = Value
        End Set
    End Property
#End Region

#Region "Overrides"
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
#End Region

End Class


Friend Class LegendItem

    Implements IDisposable

#Region "Declarations"
    Private m_Text As String = String.Empty
    Private m_Color As Color = Color.Empty
    Private m_LegendRect As RectangleF
    Private m_Font As New Font("Microsoft Sans Serif", 8.25)
    Private m_ForeColor As Color = Color.Black
#End Region

#Region "Implementations"
    Friend Sub Dispose() Implements IDisposable.Dispose
        m_Font.Dispose()
    End Sub
#End Region

#Region "Constructors"
    Friend Sub New(ByVal lgText As String, ByVal lgColor As Color, ByVal lgFont As Font, ByVal lgFColor As Color)
        MyClass.New(lgText, lgColor, lgFont)
        m_ForeColor = lgFColor
    End Sub

    Friend Sub New(ByVal lgText As String, ByVal lgColor As Color, ByVal lgFColor As Color)
        MyClass.New(lgText, lgColor)
        m_ForeColor = lgFColor
    End Sub

    Friend Sub New(ByVal lgText As String, ByVal lgColor As Color, ByVal lgFont As Font)
        MyClass.New(lgText, lgColor)
        m_Font = lgFont
    End Sub

    Friend Sub New(ByVal lgText As String, ByVal lgFont As Font)
        MyClass.New(lgText)
        m_Font = lgFont
    End Sub

    Friend Sub New(ByVal lgText As String, ByVal lgColor As Color)
        MyClass.New(lgText)
        m_Color = lgColor
    End Sub

    Friend Sub New(ByVal lgText As String)
        m_Text = lgText
    End Sub
#End Region

#Region "Properties"
    Friend ReadOnly Property LegendText() As String
        Get
            Return m_Text
        End Get
    End Property

    Friend ReadOnly Property LegendColor() As Color
        Get
            Return m_Color
        End Get
    End Property

    Friend ReadOnly Property LegendFont() As Font
        Get
            Return m_Font
        End Get
    End Property

    Friend ReadOnly Property LegendFColor() As Color
        Get
            Return m_ForeColor
        End Get
    End Property

    Friend Property LegendRect() As RectangleF
        Get
            Return m_LegendRect
        End Get
        Set(ByVal Value As RectangleF)
            m_LegendRect = Value
        End Set
    End Property
#End Region

End Class

Project Homepage: