Results 1 to 10 of 10

Thread: Date Time Picker BackColor?

Hybrid View

  1. #1
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    I read something in the msdn about theme support and that seems to be one of the ones that doesn't support it. I don't know why it wouldn't change colors though since the property is available.

    it wouldn't work for me either.

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Talking Re: Date Time Picker BackColor?

    This one works:

    VB Code:
    1. Imports System.ComponentModel
    2. Public Class ColouredDateTimePicker
    3.     Inherits DateTimePicker
    4.  
    5.  
    6. #Region " Component Designer generated code "
    7.  
    8.     Public Sub New(ByVal Container As System.ComponentModel.IContainer)
    9.         MyClass.New()
    10.  
    11.         'Required for Windows.Forms Class Composition Designer support
    12.         Container.Add(Me)
    13.     End Sub
    14.  
    15.     Public Sub New()
    16.         MyBase.New()
    17.  
    18.         'This call is required by the Component Designer.
    19.         InitializeComponent()
    20.  
    21.         'Add any initialization after the InitializeComponent() call
    22.  
    23.     End Sub
    24.  
    25.     'Component overrides dispose to clean up the component list.
    26.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    27.         If disposing Then
    28.             If Not (components Is Nothing) Then
    29.                 components.Dispose()
    30.             End If
    31.         End If
    32.         MyBase.Dispose(disposing)
    33.     End Sub
    34.  
    35.     'Required by the Component Designer
    36.     Private components As System.ComponentModel.IContainer
    37.  
    38.     'NOTE: The following procedure is required by the Component Designer
    39.     'It can be modified using the Component Designer.
    40.     'Do not modify it using the code editor.
    41.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    42.  
    43.     End Sub
    44.  
    45. #End Region
    46.  
    47.     Private _backBrushColour As SolidBrush
    48.  
    49.     Protected Overrides Sub WndProc(ByRef m As Message)
    50.         Const WM_ERASEBKGND As Int32 = &H14
    51.         If m.Msg = WM_ERASEBKGND Then
    52.             Dim g As Graphics = Graphics.FromHdc(m.WParam)
    53.             If _backBrushColour Is Nothing Then
    54.                 _backBrushColour = New SolidBrush(Me.BackColor)
    55.             End If
    56.             g.FillRectangle(_backBrushColour, Me.ClientRectangle)
    57.             g.Dispose()
    58.         Else
    59.             MyBase.WndProc(m)
    60.         End If
    61.     End Sub
    62.  
    63.     <Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    64.     Public Overrides Property BackColor() As Color
    65.         Get
    66.             Return MyBase.BackColor
    67.         End Get
    68.         Set(ByVal Value As Color)
    69.             If Not _backBrushColour Is Nothing Then
    70.                 _backBrushColour.Dispose()
    71.             End If
    72.             MyBase.BackColor = Value
    73.             _backBrushColour = New SolidBrush(Me.BackColor)
    74.             Me.Invalidate()
    75.         End Set
    76.     End Property
    77. End Class
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3
    Lively Member
    Join Date
    Aug 2007
    Posts
    88

    Re: Date Time Picker BackColor?

    Ok, it has been awhile since this was posted, but it looks it will do what I want… but here is my rookie question: How is the public class used? I have created a new class document and copied this code into it. Now how do I invoke (I am not sure if this is the right word) the class?

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width