15 November 2007

Super Duper DateTimePicker

For a C# WinForm project, I've always looked for a similar implementation of a control (that's GPLed or whatever) and then tweaking it to fit my (or my clients') needs. Don't we all do that these days with awesome websites such as codeproject.com, csharpcorner.com, 4guysfromrolla.com, dotnetkicks.com, etc, etc

Let's do a DateTimePicker.. while its a VAST improvement over validating date/times and mask controls on VB6 *shudder* there's a lot of missing items to it. First is the ability to allow blank dates. Come on EVERY single datetimepicker must have a date? So came across this control on codeproject.com -- nullableDateTimePicker.cs. Sweeeeet!!

As I am banging away coding and having fun with the nullableDateTimePicker control... a nasty thing bolted me back into reality. The Enabled = false on *ANY* of the controls that comes with VS.NET shaded the text so bad that it's so similar to the color of the default form's background. What the heck?

Here we go again... Sure, we can make a TextBox1.ReadOnly = true; -- shaded background with black text, but pretty much the rest of controls don't have a "ReadOnly" property!

So found a ReadOnlyComboBox, perfect...

Uh-oh, we need to make a nullableDateTimePicker have a ReadOnly property. Using the concept behind the ReadOnlyComboBox, I combined two of his (yea, the same guy) code into one to make a super-duper nullableDateTimePicker control. [Download zipped NullableDateTimePicker.cs]

Where are you, Claudio?? Hope to see you around in one of those .NET conventions!

3 shouts:

kjward said...

how 'bout a extra super duper datetimepicker that has the dates out of the min-max range a selectable different color. and if you're really ambitious, one that tells you in a real-time tooltip, how many days the date the mouse is over is from today?

how would i begin to approach these "enhancements" if i wanted to try for myself?

rob said...

Those are pretty neat ideas there! Go ahead and try those enhancements and link to your version of the code. Holler if you need help.

ozba said...

The ReadOnly Property causes the DateTimePicker to be blank, with the back color of its container, rather then be grayed (with the option to change its color) like the text box ReadOnly property for example.