Click here to Skip to main content
12,620,909 members (32,570 online)
Click here to Skip to main content

Stats

82.9K views
3K downloads
66 bookmarked
Posted

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

, 8 Feb 2012 CPOL
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.Drawing.Drawing2D
Imports System.ComponentModel
Imports System.Drawing.Design
Imports System.Windows.Forms.Design

Public Class HatchStyleEditor
    Inherits UITypeEditor

    ' Indicate that we display a dropdown.
    Public Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle
        Return UITypeEditorEditStyle.DropDown
    End Function

    ' Edit a line style
    Public Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object
        ' Get an IWindowsFormsEditorService object.
        Dim editor_service As IWindowsFormsEditorService = _
            CType(provider.GetService(GetType(IWindowsFormsEditorService)), _
            IWindowsFormsEditorService)
        If editor_service Is Nothing Then
            Return MyBase.EditValue(context, provider, value)
        End If

        ' Pass the UI editor the current property value

        Dim colorA, colorB As Color
        If context.Instance.GetType Is GetType(gTimePicker) Then
            Dim Instance As gTimePicker = CType(context.Instance, gTimePicker)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)

        ElseIf context.Instance.GetType Is GetType(gDateTimePicker) Then
            Dim Instance As gDateTimePicker = CType(context.Instance, gDateTimePicker)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)

        ElseIf context.Instance.GetType Is GetType(gTimeBox) Then
            Dim Instance As gTimeBox = CType(context.Instance, gTimeBox)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)
        End If

        ' Convert the value into a BorderStyles value.
        Dim hatch_style As HatchStyle = DirectCast(value, HatchStyle)

        ' Make the editing control.
        Dim editor_control As New HatchStyleListBox(hatch_style.ToString, _
            colorA, colorB, editor_service)
        ' Display the editing control.
        editor_service.DropDownControl(editor_control)

        ' Save the new results.
        Return CType(System.Enum.Parse(GetType(HatchStyle), editor_control.Text, True), HatchStyle)
    End Function

    Public Overrides ReadOnly Property IsDropDownResizable() As Boolean
        Get
            Return MyBase.IsDropDownResizable
        End Get
    End Property

    Public Overrides Function GetPaintValueSupported(ByVal context As ITypeDescriptorContext) As Boolean
        Return True
    End Function

    Public Overrides Sub PaintValue(ByVal e As PaintValueEventArgs)
        Dim hatch As HatchStyle = CType(e.Value, HatchStyle)
        ' Pass the UI editor the current property value

        Dim colorA, colorB As Color
        Dim nullalpha As Integer

        If e.Context.Instance.GetType Is GetType(gTimePicker) Then
            Dim Instance As gTimePicker = CType(e.Context.Instance, gTimePicker)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)
            nullalpha = Instance.NullAlpha

        ElseIf e.Context.Instance.GetType Is GetType(gDateTimePicker) Then
            Dim Instance As gDateTimePicker = CType(e.Context.Instance, gDateTimePicker)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)
            nullalpha = Instance.NullAlpha

        ElseIf e.Context.Instance.GetType Is GetType(gTimeBox) Then
            Dim Instance As gTimeBox = CType(e.Context.Instance, gTimeBox)
            colorA = Color.FromArgb(Instance.NullAlpha, Instance.NullColorA)
            colorB = Color.FromArgb(Instance.NullAlpha, Instance.NullColorB)
            nullalpha = Instance.NullAlpha
        End If

        Using br As Brush = New HatchBrush(hatch, Color.FromArgb(nullalpha, colorA), Color.FromArgb(nullalpha, colorB))
            e.Graphics.FillRectangle(br, e.Bounds)
        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.

License

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

Share

About the Author

SSDiver2112
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...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 8 Feb 2012
Article Copyright 2009 by SSDiver2112
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid