Click here to Skip to main content
13,596,324 members
Click here to Skip to main content

Tagged as


66 bookmarked
Posted 21 Aug 2009
Licenced CPOL

gTimePicker- Control to Pick a Time Value (VB.NET)

, 8 Feb 2012
Stop using the DateTimePicker for time values. This control makes it easy to pick a time, and if you act now, get the matching Nullable gDateTimePicker at no extra cost.
Imports System.Windows.Forms.Design
Imports System.Drawing.Drawing2D
Imports System.ComponentModel

<ToolboxItem(False)> _
Public Class ColorComboBox
    Inherits ComboBox

    Public Event HoverSelect(ByVal sender As Object, ByVal fontcolor As String)

    Private Known_Color() As String = Split("Transparent,Black,DimGray,Gray,DarkGray,Silver,LightGray,Gainsboro," & _
    "WhiteSmoke,White,RosyBrown,IndianRed,Brown,Firebrick,LightCoral,Maroon,DarkRed,Red,Snow,MistyRose," & _
    "Salmon,Tomato,DarkSalmon,Coral,OrangeRed,LightSalmon,Sienna,SeaShell,Chocalate,SaddleBrown,SandyBrown," & _
    "PeachPuff,Peru,Linen,Bisque,DarkOrange,BurlyWood,Tan,AntiqueWhite,NavajoWhite,BlanchedAlmond,PapayaWhip," & _
    "Mocassin,Orange,Wheat,OldLace,FloralWhite,DarkGoldenrod,Cornsilk,Gold,Khaki,LemonChiffon,PaleGoldenrod," & _
    "DarkKhaki,Beige,LightGoldenrodYellow,Olive,Yellow,LightYellow,Ivory,OliveDrab,YellowGreen,DarkOliveGreen," & _
    "GreenYellow,Chartreuse,LawnGreen,DarkSeaGreen,ForestGreen,LimeGreen,PaleGreen,DarkGreen,Green,Lime," & _
    "Honeydew,SeaGreen,MediumSeaGreen,SpringGreen,MintCream,MediumSpringGreen,MediumAquaMarine," & _
    "YellowAquaMarine,Turquoise,LightSeaGreen,MediumTurquoise,DarkSlateGray,PaleTurquoise,Teal,DarkCyan,Aqua," & _
    "Cyan,LightCyan,Azure,DarkTurquoise,CadetBlue,PowderBlue,LightBlue,DeepSkyBlue,SkyBlue,LightSkyBlue," & _
    "SteelBlue,AliceBlue,DodgerBlue,SlateGray,LightSlateGray,LightSteelBlue,CornflowerBlue,RoyalBlue," & _
    "MidnightBlue,Lavender,Navy,DarkBlue,MediumBlue,Blue,GhostWhite,SlateBlue,DarkSlateBlue,MediumSlateBlue," & _
    "MediumPurple,BlueViolet,Indigo,DarkOrchid,DarkViolet,MediumOrchid,Thistle,Plum,Violet,Purple,DarkMagenta," & _
    "Magenta,Fuchsia,Orchid,MediumVioletRed,DeepPink,HotPink,LavenderBlush,PaleVioletRed,Crimson,Pink,LightPink", ",")

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

        'Add your custom paint code here
    End Sub

    Protected Overrides Sub OnHandleCreated(ByVal e As System.EventArgs)
        If Not DesignMode Then LoadColors()
    End Sub

    Public Sub New()
        ' This call is required by the Windows Form Designer.
        ' Add any initialization after the InitializeComponent() call.
        DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
        AddHandler DrawItem, New DrawItemEventHandler(AddressOf List_DrawItem)

        With Me
            .DropDownWidth = 150
            .AutoSize = False
            .Width = 100
            .DropDownStyle = ComboBoxStyle.DropDownList
            .DropDownHeight = 250
        End With
    End Sub

    Public Sub LoadColors()
        With Me
        End With

    End Sub

    ' Handle the DrawItem event for an owner-drawn List.
    Private Sub List_DrawItem(ByVal sender As Object, _
        ByVal e As DrawItemEventArgs)

        If e.Index = -1 Then Exit Sub

        Dim CBox As ComboBox = CType(sender, ComboBox)
        Dim itemString As String = CType(CBox.Items(e.Index), String)

        Dim rect As Rectangle
        If (e.State And DrawItemState.ComboBoxEdit) = DrawItemState.ComboBoxEdit Then
            e.Graphics.FillRectangle(New SolidBrush(BackColor), e.Bounds)

        ElseIf (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
            rect = New Rectangle(e.Bounds.X + 1, e.Bounds.Y, e.Bounds.Width - 3, e.Bounds.Height - 2)
            e.Graphics.FillRectangle(Brushes.Beige, rect)
            e.Graphics.DrawRectangle(Pens.Blue, rect)
            RaiseEvent HoverSelect(Me, itemString)

            e.Graphics.FillRectangle(New SolidBrush(BackColor), e.Bounds)
        End If

        'Draw a Color Swatch
        Using myBrush As New SolidBrush(Color.FromName(itemString))

            e.Graphics.FillRectangle(myBrush, e.Bounds.X + 3, e.Bounds.Y + 2, 20, e.Bounds.Height - 5)
            e.Graphics.DrawRectangle(Pens.Black, e.Bounds.X + 3, e.Bounds.Y + 2, 19, e.Bounds.Height - 6)

            ' Draw the text in the item.
            e.Graphics.DrawString(itemString, New Font("Microsoft Sans Serif", 8.25), _
                Brushes.Black, e.Bounds.X + 25, e.Bounds.Y + 1)
        End Using
    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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
I first got hooked on programing with the TI994A. After it finally lost all support I reluctantly moved to the Apple IIe. Thank You BeagleBros for getting me through. I wrote programs for my Scuba buisness during this time. Currently I am a Database manager and software developer. I started with VBA and VB6 and now having fun with VB.NET/WPF/C#...

You may also be interested in...

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180621.3 | Last Updated 8 Feb 2012
Article Copyright 2009 by SSDiver2112
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid