Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:windowswinsxs). 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...