Results 1 to 10 of 10

Thread: Date Time Picker BackColor?

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Exclamation Date Time Picker BackColor?

    Place a DateTimePicker on your form.

    Then place this code in the Form Load event

    VB Code:
    1. Me.DateTimePicker1.BackColor = System.Drawing.Color.Tomato

    Run the application.

    Why doesn't it work?

  2. #2
    Member
    Join Date
    Mar 2004
    Location
    Middle of nowhere
    Posts
    45
    Umm... Dont think you can change the background of the date bar itself, but if you want to change the selection part you can do:
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Me.DateTimePicker1.CalendarMonthBackground = System.Drawing.Color.Blue
    4.         Me.DateTimePicker1.CalendarTitleBackColor = System.Drawing.Color.Red
    5.         Me.DateTimePicker1.CalendarForeColor = System.Drawing.Color.Black
    6.     End Sub
    and then of course change colors to yoru desired color. If i figure out how to change the bar itself though, i'll be sure to tell ya...


    ---Flac
    Everything great once started with the words "That will never catch on, you shouldnt even bother" be great, go against the crowed, do something stupid, you might become famous.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by Flac
    Umm... Dont think you can change the background of the date bar itself, but if you want to change the selection part you can do:
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.  
    3.         Me.DateTimePicker1.CalendarMonthBackground = System.Drawing.Color.Blue
    4.         Me.DateTimePicker1.CalendarTitleBackColor = System.Drawing.Color.Red
    5.         Me.DateTimePicker1.CalendarForeColor = System.Drawing.Color.Black
    6.     End Sub
    and then of course change colors to yoru desired color. If i figure out how to change the bar itself though, i'll be sure to tell ya...


    ---Flac
    Thanks for responding, but I was looking to color just the date bar, as in my previous post.

    Any ideas as to why it's not possible, btw?

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by mendhak
    Any ideas as to why it's not possible, btw?
    Not sure why but you might try overriding BackColor of the DTP and provide your own implementation by creating your own User Control .

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

  6. #6
    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.

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

  8. #8
    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

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Date Time Picker BackColor?

    Dim cdtp As New ColouredDateTimePicker?

    Or do you want to create a new control project and add that reference?

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

    Re: Date Time Picker BackColor?

    Ok... I think I get it. I have to create a new control and locate it on the form in code. I was trying to apply the ColouredDateTimePicker to an existing datetimepicker on a form. I will give this a try. 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