Archive for February, 2009

You can see a first glimpse of the new user interface for Visual Studio 2010 on the following Microsoft employee blog. Looks quite nice and makes use of WPF for the editing window.

Visual Studio 2010

Starting afresh the new KryptonDateTimePicker is starting to look like the finished product although there is still one major feature yet to be completed. I have tried to add the same set of properties as the standard windows version to make it easy to upgrade to the new control. I hope in most cases a simple find/replace of the class name will be enough to get people up and working. Although I cannot promise there will not be edge cases where you need to spend extra time manually checking/updating.

Here we have the control displayed with each of the four Format property settings of Long, Short, Time and Custom. The associated CustomFormat is defined as “MMMM dd ‘at’ hh:mm tt“.

Clicking the drop down button presents the new KryptonMonthCalendar control inside a KryptonContextMenu instance that allows the selection of a new date. The DropDown event is fired before the calendar is displayed and allows you to customize the context menu with additional menu items as required. This could be very handy if you need to add extra options such as predefined date selection.

As with the standard control you can show a check box that allows the user to specify that the date should be null. In fact I have added an extra property called ValueNullable that will help with annoying data binding scenarios. The Value property works like the standard control and always returns a DateTime value but ValueNullable will return DBNull when the check box is cleared and return a DateTime when the check box is set. That should making binding against database columns easier.

Use ShowUpDown to show a pair of spin buttons instead of the default drop down button. As with most Krypton controls you can use ButtonSpec definitions to add extra buttons to the control area.


Text Editing

The one feature currently missing, and my next task, is the ability to modify the text area using the keyboard. I need to take the focus and highlight the different fragments of text such as just the month, day, hours and so forth. Then allow the up/down buttons and other keyboard actions to modify the value. This requires parsing the format and working out the correct drawing of different sections. Not that hard but it requires quite a bit work to get it working smoothly.

Thanks for all the suggestions and ideas people have presented in the blog and also in the forums about ways to go about getting the DateTimePicker to work under visual styles of Vista. None of them actually solves the problem 100% and so I have decided to just write the control from scratch instead.

Even if all the hacks could be make to give the correct presentation if would still be unpleasant having to hope that they continue to work for all future versions of Windows. It is much more work to start from scratch but I hope it will pay off in the long run and allow a greater level of flexibility. Adding additional functionality will be easier when you have the full source code and can do anything you want.

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.

When developing the standalone KryptonMonthCalendar I ensured it was compatible with the mechanism used to place its drawing code as an element inside the KryptonContextMenu. So you can embed a calendar inside the context menu to create rich date selection functionality. Here you can see a simple example where the calendar is inside a menu that is associated with the drop down button.