Click here to Skip to main content
12,349,379 members (31,380 online)
Click here to Skip to main content

Stats

139.9K views
807 downloads
38 bookmarked
Posted

LEDClock - Windows Forms Composite Control

, 4 Jun 2002
This article explains how to build Popup editor and link it to an appropriate property in Properties Window
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms.Control

Public Class LEDControl
    Inherits System.Windows.Forms.Control

    Private mNumber As Integer = 0

#Region " Component Designer generated code "

    Public Sub New()
        MyBase.New()

        InitializeComponent()

        setstyle(ControlStyles.ResizeRedraw, True)

    End Sub

    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

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

#End Region

    Public Property Number() As Integer
        Get
            Return mNumber
        End Get
        Set(ByVal Value As Integer)
            If Value >= 0 And Value < 11 Then
                Dim old As Integer = mNumber
                mNumber = Value
                Me.Invalidate()
            End If
        End Set
    End Property

    Public Sub Inrease()
        If Me.Number <> 9 Then
            Me.Number += 1
        Else
            Me.Number = 0
        End If
    End Sub

    Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(pe)

        Dim g As Graphics = pe.Graphics
        DrawNumber(g, mNumber)

    End Sub

    Private Sub DrawNumber(ByVal g As Graphics, ByVal num As Integer)
        Dim p As New Pen(Me.ForeColor)
        Select Case num
            Case 0

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

                'BOTTOM LEFT
                g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
                g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)

            Case 1

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 2

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM LEFT
                g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
                g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)

            Case 3

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 4

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 5

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 6

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

                'BOTTOM LEFT
                g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
                g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)

            Case 7

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 8

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

                'BOTTOM LEFT
                g.DrawLine(p, 2, Me.Height \ 2 + 2, 2, Me.Height - 5)
                g.DrawLine(p, 3, Me.Height \ 2 + 1, 3, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height \ 2 + 2, 4, Me.Height - 5)

            Case 9

                'TOP
                g.DrawLine(p, 5, 2, Me.Width - 5, 2)
                g.DrawLine(p, 4, 3, Me.Width - 4, 3)
                g.DrawLine(p, 5, 4, Me.Width - 5, 4)

                'MIDDLE
                g.DrawLine(p, 5, Me.Height \ 2 - 1, Me.Width - 5, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, Me.Height \ 2, Me.Width - 4, Me.Height \ 2)
                g.DrawLine(p, 5, Me.Height \ 2 + 1, Me.Width - 5, Me.Height \ 2 + 1)

                'BOTTOM
                g.DrawLine(p, 5, Me.Height - 4, Me.Width - 5, Me.Height - 4)
                g.DrawLine(p, 4, Me.Height - 3, Me.Width - 4, Me.Height - 3)
                g.DrawLine(p, 5, Me.Height - 2, Me.Width - 5, Me.Height - 2)

                'TOP LEFT
                g.DrawLine(p, 2, 5, 2, Me.Height \ 2 - 2)
                g.DrawLine(p, 3, 4, 3, Me.Height \ 2 - 1)
                g.DrawLine(p, 4, 5, 4, Me.Height \ 2 - 2)

                'TOP RIGHT
                g.DrawLine(p, Me.Width - 4, 5, Me.Width - 4, Me.Height \ 2 - 2)
                g.DrawLine(p, Me.Width - 3, 4, Me.Width - 3, Me.Height \ 2 - 1)
                g.DrawLine(p, Me.Width - 2, 5, Me.Width - 2, Me.Height \ 2 - 2)

                'BOTTOM RIGHT
                g.DrawLine(p, Me.Width - 2, Me.Height \ 2 + 2, Me.Width - 2, Me.Height - 5)
                g.DrawLine(p, Me.Width - 3, Me.Height \ 2 + 1, Me.Width - 3, Me.Height - 4)
                g.DrawLine(p, Me.Width - 4, Me.Height \ 2 + 2, Me.Width - 4, Me.Height - 5)

            Case 10

                Dim p2 As New Pen(Me.ForeColor, 2)
                g.DrawRectangle(p2, Me.Width \ 2 - 1, Me.Height \ 4 - 2, 2, 2)
                g.DrawRectangle(p2, Me.Width \ 2 - 1, 3 * Me.Height \ 4 - 2, 2, 2)
                p2 = Nothing

        End Select

        p = Nothing

    End Sub

    Protected Overrides ReadOnly Property DefaultSize() As System.Drawing.Size
        Get
            Dim mSize As System.Drawing.Size = New System.Drawing.Size(32, 32)
            Return mSize
        End Get
    End Property

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Andelko Pavelic
Australia Australia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 5 Jun 2002
Article Copyright 2002 by Andelko Pavelic
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid