In case this information will be helpful to anybody in the future, I finally determined the cause of the current date not bolding in Windows 7. I discovered the line of code that prevents the current date from bolding in Windows 7 even though the line of code does not prevent the current date from bolding in Virtual PC/Windows XP mode.
In the real Windows application, I searched for any code that might be the culprit and then tested in a lil’ test application project. I used Visual Studio 2005 for my test application just as the real application was created in Visual Studio 2005. My review of the real app’s code and my testing determined that when I comment out the following line of code in the real Windows app, the current date is bolded in Windows 7 whereas if I have this line of code the current date is not bolded in the System.Windows.Forms.MonthCalendar control in Windows 7:
this.calDate.MaxDate = System.DateTime.Today;
The name of the MonthCalendar control in this Windows app is calDate
Here is code from a lil’ test app that shows how this line of code is the culprit. If you run the lil’ test app with this line of code “this.monthCalendar1.MaxDate = System.DateTime.Today;” and then run the test app without this line of code on Windows 7, you will see that having this line of code prevents the current date from bolding on Windows 7. There is nothing in this Visual Studio 2005 project except a form and the MonthCalendar control on the form. There are no other controls on the form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ToTestCurrentDateBolding
{
public partial class Form1 : Form
{
public Form1()
{
Application.EnableVisualStyles();
InitializeComponent();
this.monthCalendar1.MaxDate = System.DateTime.Today;
this.Load += new System.EventHandler(this.Form1_Load);
}
private void Form1_Load(object sender, System.EventArgs e)
{
//Now I have added in this test project to set the MaxDate of the calendar control
//to current date to see if this affects the bolding of the current date on Windows 7.
//In our real app, we set the MaxDate to System.DateTime.Today.
//Using the following code, on Windows XP mode the current date is bolded still.
//On Windows 7, the current date is NOT bolded.
//SO HAVING THE LINE OF CODE "this.monthCalendar1.MaxDate = System.DateTime.Today;" IS
//THE REASON WHY THE CURRENT DATE IS NOT BOLDED IN WINDOWS 7!!! When I remove
//the line of code "this.monthCalendar1.MaxDate = System.DateTime.Today;" the
//current date IS BOLDED in Windows 7.
DateTime dt = DateTime.Now;
monthCalendar1.AddBoldedDate(dt);
monthCalendar1.UpdateBoldedDates();
//The following code works on BOTH Windows 7 and Windows XP mode
//when the Max Selection Count is the default 7 for the MonthCalendar
//control. I am trying this code when I change the Max Selection Count
//to 1 since this is the Maximum Selection Count in our real Windows application.
//With Max Selection Count set to 1, the current date is bolded on Windows XP mode.
//With Max Selection Count set to 1, on Windows 7 the current date DOES show as bold.
//DateTime dt = DateTime.Now;
//monthCalendar1.AddBoldedDate(dt);
//monthCalendar1.UpdateBoldedDates();
//This bolds the current date in Virtual PC/Windows XP mode.
//This ALSO bolds the current date in Windows 7.
//This code works on both Windows 7 and Virtual PC/Windows XP mode
//when I do NOT have the line of code Application.EnabledVisualStyles() that is in the main form of the real app.
//DateTime dt = DateTime.Now;
//monthCalendar1.AddBoldedDate(dt);
//monthCalendar1.UpdateBoldedDates();
//When I DO have the line of code Application.EnabledVisualStyles() like in the main form of the real app,
//this code does bold current date in Windows XP mode AND
//this code DOES bold the current date in Windows 7.
//DateTime dt = DateTime.Now;
//monthCalendar1.AddBoldedDate(dt);
//monthCalendar1.UpdateBoldedDates();
}
}
}
From the Form1.Designer.cs file, here is some code:
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
this.SuspendLayout();
//
// monthCalendar1
//
this.monthCalendar1.Location = new System.Drawing.Point(210, 138);
this.monthCalendar1.MaxSelectionCount = 1;
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(628, 477);
this.Controls.Add(this.monthCalendar1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
So anyway, having the MaxDate property of the MonthCalendar control set to the current date prevents the bolding of the current date in Windows 7 even though setting the MaxDate property to current date does NOT prevent the bolding of the current date in Virtual PC/Windows XP mode. The MaxDate property of the MonthCalendar control gets or sets the maximum allowable date (for example, it sets the maximum allowable date that the user can select).
In the real Windows app, the date range is for the calibration of probes on an oven control and of course it is not possible for a human being to calibrate the probes of an oven control in the future and therefore it is not necessary to allow the user to select a future date to see a report of the probe calibrations of the selected ovens for the selected date range. It does no harm though to remove this line of code and I am removing so that the current date will show as bold in Windows 7 if a calibration was done on that current date just like the current date showed in Windows XP mode/Virtual PC when the current date should be bolded per the data in the database.
Is this a bug in Windows 7? I do not know why setting the MaxDate of the MonthCalendar control to the current date would prevent the bolding of the current date in Windows 7 when it does NOT prevent the bolding of the current date in Virtual PC/Windows XP mode.
I just wanted to post this answer to the problem and the resolution in case anybody in the future will find it helpful.
Ciao,
Hviezdoslav