Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Calendar in DateTimePicker Control?

I think the question is simple and clear. The image bellow is my current progress.

enter image description here

As you can see, customized version is my extended DateTimePicker Control. The control changes button and border color depending on the Focused value. The dropped down calendar is the next thing I want to style.

I just don't know where to start because nothing seams to be working. I wouldn't change much at least border color, font color and etc...

like image 523
Dino Avatar asked Mar 13 '23 20:03

Dino


2 Answers

You have very few options. The drop-down calender is a MonthCalendar control, created dynamically by DTP when you click the dropdown button Destroyed again when the user dismisses it. MonthCalendar is one of the common controls, built into Windows, written in C++ and stored in comctl32.dll. Your app uses the v6.0 version, stored in the side-by-side cache (c:\windows\winsxs). The .NET class is just a wrapper, it doesn't change the way it looks or works.

Notable is that it changed a great deal between Windows versions, always something you have to watch out for, it is used in highly visible places in Windows. It is the first common control that a user ever interacts with when he installs Windows. And used in clock on the taskbar. Windows 10 is the first version that no longer does, the Win8 look-and-feel is frozen and unlikely to ever change again.

As noted, the dropdown is dynamically created. You can get a handle to the MonthCalendar window by sending the DTM_GETMONTHCAL message, do so in an event handler for the DropDown event. At that point the window handle is valid but the calendar not yet visible, the proper time to tinker with it.

From there you can send the MCM messages to configure the calendar. As you can tell, very slim pickings as far as styling goes. You have MCM_SETCALENDARBORDER to change the border thickness and MCM_SETCOLOR to alter colors. The latter only works if the visual style renderer is disabled, it is not in your app. Technically you can call SetWindowTheme() to disable the visual style renderer so MCM_SETCOLOR will work again. But that turns the clock back to the year 2000, it will look quite dinosauric.

That's all, not enough to ever make anybody happy. Consider embedding a WPF DatePicker to get more control over styling.

like image 50
2 revs Avatar answered Mar 25 '23 00:03

2 revs


There are a bunch of properties that affect the display of the calendar, such as:

  • CalendarFont
  • CalendarForeColor
  • CalendarMonthBackground
  • CalendarTitleBackColor

etc.

See MSDN for more info.

That said, the DateTimePicker control is (in)famous for not applying changes from these properties. It applies them only when visual styles on the whole form is turned off and then you get that ugly beveled look with applied colors of your choosing -- but still ugly.

like image 32
reggie Avatar answered Mar 25 '23 00:03

reggie