Click here to Skip to main content
13,593,266 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 29 Jul 2011
Licenced CPOL

A simple solution for changing a DateTimerPicker background color

, 29 Jul 2011
Rate this:
Please Sign up or sign in to vote.
How to change the background color of a DateTimerPicker control.

This is an answer to a question in comments section of the following article (I can't otherwise find a link to simply respond to that question): A DateTimePicker with working BackColor, by Vincenzo Rossi.

I wanted to come up with a simpler solution that has no limitations. I hit the same problem and came to the same conclusions as in the original post. However I didn't like the limitations, namely that one couldn't directly edit the days/months/years in the control anymore. Then I found a great solution here:

Basically, you create a control inheriting from DateTimePicker and add this override:

const int WM_ERASEBKGND = 0x14;
protected override void WndProc(ref System.Windows.Forms.Message m)
     if(m.Msg == WM_ERASEBKGND)
       Graphics g = Graphics.FromHdc(m.WParam);
       g.FillRectangle(new SolidBrush(_backColor), ClientRectangle);
     base.WndProc(ref m);

(where _backColor is the color of your choice...)

If you want to change the color, simply call the Invalidate() method of your DateTimePicker after changing _backColor. To me, that works wonderful, without any limitations.


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


About the Author

Belgium Belgium
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 1 not work under vista/win7 Pin
redcheek24-Aug-11 18:37
memberredcheek24-Aug-11 18:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180618.1 | Last Updated 29 Jul 2011
Article Copyright 2011 by folk007
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid