D
DS
I seem to have run into another strange anomaly with the monthCalendar
control. I want to display 6 months at time with either the first half
of the year (January-June) or the later half of the year (July-Dec)
being rendered- depending on where todays date falls. I also want
today's date to be selected. This poses a problem. Refer to the code below.
Add a call to createCalendar() to your constructor (AFTER the
InitializeComponents() call). If you leave it as is without calling
selectToday(), it displays the correct 6-month block starting with the
correct month. If however you uncomment selectToday(), it displays
Nov-April, which is NOT what I want, so comment it back again.
Next try adding a button to the form, and in the onClick event, add a
call to selectToday(), and this works perfectly-- the correct 6-month
block is displayed (July-Dec), and today is selected.
Another option is to uncomment selectToday() from createCalendar(), but
remove createCalendar() from the constructor and add the call to the
button onClick event instead. Once again this works perfectly.
So in both cases it works if its called from a button click, but not
from the constructor. Unfortunately this isn't practical because I need
it to show without a person hitting a button. Instead of calling it from
a button onClick, add it to a backGroundWorker process and it also works
correctly, but its not right to futz around with controls in another
thread. It just seems to mess up when its called before the form is
displayed or something strange like that. Whats going on here?
Thanks in advance,
-DS
-- code below --
MonthCalendar mc;
private void createCalendar()
{
mc = new MonthCalendar();
mc.CalendarDimensions = new Size(3,2);
mc.Location = new Point(0, 0);
mc.MaxSelectionCount = 1;
mc.ScrollChange = 1;
if (DateTime.Today.Month <= 6)
mc.SetDate(DateTime.Parse("1 January " + DateTime.Today.Year.ToString()));
else
mc.SetDate(DateTime.Parse("1 July " + DateTime.Today.Year.ToString()));
this.Controls.Add(mc);
//selectToday();
}
private void selectToday()
{
mc.SetDate(DateTime.Today);
}
control. I want to display 6 months at time with either the first half
of the year (January-June) or the later half of the year (July-Dec)
being rendered- depending on where todays date falls. I also want
today's date to be selected. This poses a problem. Refer to the code below.
Add a call to createCalendar() to your constructor (AFTER the
InitializeComponents() call). If you leave it as is without calling
selectToday(), it displays the correct 6-month block starting with the
correct month. If however you uncomment selectToday(), it displays
Nov-April, which is NOT what I want, so comment it back again.
Next try adding a button to the form, and in the onClick event, add a
call to selectToday(), and this works perfectly-- the correct 6-month
block is displayed (July-Dec), and today is selected.
Another option is to uncomment selectToday() from createCalendar(), but
remove createCalendar() from the constructor and add the call to the
button onClick event instead. Once again this works perfectly.
So in both cases it works if its called from a button click, but not
from the constructor. Unfortunately this isn't practical because I need
it to show without a person hitting a button. Instead of calling it from
a button onClick, add it to a backGroundWorker process and it also works
correctly, but its not right to futz around with controls in another
thread. It just seems to mess up when its called before the form is
displayed or something strange like that. Whats going on here?
Thanks in advance,
-DS
-- code below --
MonthCalendar mc;
private void createCalendar()
{
mc = new MonthCalendar();
mc.CalendarDimensions = new Size(3,2);
mc.Location = new Point(0, 0);
mc.MaxSelectionCount = 1;
mc.ScrollChange = 1;
if (DateTime.Today.Month <= 6)
mc.SetDate(DateTime.Parse("1 January " + DateTime.Today.Year.ToString()));
else
mc.SetDate(DateTime.Parse("1 July " + DateTime.Today.Year.ToString()));
this.Controls.Add(mc);
//selectToday();
}
private void selectToday()
{
mc.SetDate(DateTime.Today);
}