I started work on the KryptonDateTimePicker a couple of days ago and it all seemed to be going pretty well. I took the same approach as for many of the other controls and embedded the standard DateTimePicker inside a Krypton container that provides the border. Here you can see a picture with the standard control at the top and the Kryptonized version below…

The next step was to update the background color to match the palette setting. This is where things start to go downhill as I discover the DateTimePicker does not actually have a BackColor property. No problem I think to myself, I just need to override the WndProc and handle the WM_ERASEBKGND message myself. Draw the background in the required color myself and we are good to go.
Well not so fast. Although my code is executed it makes no difference to the displayed background. This is odd so I do some Google research and discover this is a well known bug in the control. Apparently the WM_ERASEBKGND approach works with controls that do not have visual styles enabled but fails otherwise. So I removed the application level call to EnableVisualStyles and tried again. Yep, now it draws the background correctly using my code. In practice almost all .NET applications call EnableVisualStyles when they are started so I need a solution that does not insist this line of code is removed from apps.
There is one last possibility which is to call SetWindowTheme(Handle, “”, “”) for the control instance and so turn off visual styles just for that one individual control. This allows the rest of the application to run as it likes but ensures we get the background drawn for our KryptonDateTimePicker instance.
Unfortunately this last gasp attempt just falls short. It draws the border and drop down button of the control in the Windows Classic appearance which is exactly what I expect when visual styles are turned off. But it still stubbornly does not draw the text background using the WM_ERASEBKGND code! Close but no cigar.
Unless someone out there has a clever idea it looks like I need to scrap the work and begin again with a new approach.
February 16th, 2009 at 9:37 pm
I have a good idea, at least I can tell you what I did to create my datetimepicker, I used the mono control, it works nicely, but I have not checked the licensing information, at least you can pick up the basic idea from there, from memory its a pretty simple design and if the license does not suit you, you can always rewrite it yourself.
February 16th, 2009 at 10:18 pm
Maybe I’m a bit naive, but IMO a DateTimePicker could just be a drop down button that shows a calendar control, with a “Value” property that exposes the selected date.
The text displayed on the button is the selected date formatted according to the developer’s preference.
The only “tricky” parts would be styling the button to make it look like a datetimepicker and eventually replacing the button with a special text box for the time input.
February 17th, 2009 at 2:24 am
I think Phil already thought about using a KryptonDropDownButton/KryptonCombobox, but then you’ll have a problem users will notice. You can’t select the day, month or year and type in a new value and in the case of a combo you’ll have to replace the whole string.
The “styling the button to make it look like a datetimepicker” isn’t a problem because you can style it to look like a combo and use a custom icon (glyph) for the drop down button.
February 18th, 2009 at 6:52 am
Phil, I posted my findings in the forum, but I’m curious what you mean by : “But it still stubbornly does not draw the text background using the WM_ERASEBKGND code”. Do you mean that what you paint in WM_ERASEBKGND is not applied to the control or that it is overdrawn by something else in the downstream process?
Feel free to respond by email if you’d rather have the convo there.