Resolved MonthCalendar BoldedDates bug

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,828
Location
Norway
Programming Experience
10+
When using MonthCalendar and needing BoldedDates I discover that no dates are bolded. Research tells me this control is drawn by system, in this case Vista, and that the problem is related to Visual Styles. Visual Styles can be disabled for whole application in settings, which I don't want to do, but I can see when testing that turning off Visual Styles does resolve the problem. So I found out you can disable theming for only one window (control window) with SetWindowTheme API call. Here is a common declaration for that:
VB.NET:
Private Declare Function DeactivateWindowTheme Lib "uxtheme" Alias "SetWindowTheme" ( _
    ByVal hWnd As IntPtr, _
    Optional ByVal pszSubAppName As String = "", _
    Optional ByVal pszSubIdList As String = "") _
    As Integer
Example usage:
VB.NET:
Dim d1 As Date = Date.Now.AddDays(-1)
Dim d2 As Date = d1.AddDays(2)
Me.MonthCalendar1.BoldedDates = New Date() {d1, d2}
Me.MonthCalendar1.UpdateBoldedDates()
DeactivateWindowTheme(Me.MonthCalendar1.Handle)
Note that UpdateBoldedDates forces the control to recreate and it gets a new window handle, so you have to call DeactivateWindowTheme after each call to UpdateBoldedDates.

Tell me when bug is fixed, because now I will probably not notice :cool:
 
I just checked this again for first time since 2008, bolded dates in MonthCalendar now work properly using Windows 10. :LOL:
 
Back
Top